Skip to content

Commit

Permalink
test: update tests with the last version of jest/testing-library
Browse files Browse the repository at this point in the history
  • Loading branch information
Virtute90 committed Apr 26, 2024
1 parent 424663f commit 5a57a6d
Show file tree
Hide file tree
Showing 21 changed files with 57 additions and 60 deletions.
6 changes: 3 additions & 3 deletions test/Accordion.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import { Accordion, AccordionHeader } from '../src';
import React from 'react';
import { AccordionItem } from 'reactstrap';
import { Accordion, AccordionHeader } from '../src';

describe('Accordion component', () => {
it('should work as container for children elements', () => {
Expand Down
11 changes: 5 additions & 6 deletions test/BottomNavItem.test.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import React from 'react';
import { screen, render } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';

import { BottomNavItem, preloadIcons } from '../src';

// Icons are now async, so preload them to make it behave in an sync way
beforeAll(() => preloadIcons(['it-comment']));

// Test for breaking changes
test('Should support old link props as @deprecated', () => {
const { getByRole } = render(<BottomNavItem link={'/my-url'} />);
test('Should support old url props as @deprecated', () => {
const { getByRole } = render(<BottomNavItem url={'/my-url'} />);
expect(getByRole('link')).toHaveAttribute('href', '/my-url');
});

test('should have a testId for resilient UI changes', () => {
render(<BottomNavItem link={'/my-url'} testId={'bottom-nav-test-id'} />);
render(<BottomNavItem url={'/my-url'} testId={'bottom-nav-test-id'} />);
expect(screen.getByTestId('bottom-nav-test-id')).toBeTruthy();
});
4 changes: 2 additions & 2 deletions test/Breadcrumb.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import "@testing-library/jest-dom";
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import React from 'react';
import { Breadcrumb } from '../src';

describe('Breadcrumb component', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/Collapse.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import "@testing-library/jest-dom";
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import React from 'react';
import { Collapse } from '../src';

describe('Collapse component', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/Dimmer.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import "@testing-library/jest-dom";
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import React from 'react';

import { Dimmer } from '../src';

Expand Down
4 changes: 2 additions & 2 deletions test/DimmerButtons.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import "@testing-library/jest-dom";
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import React from 'react';

import { DimmerButtons } from '../src';

Expand Down
4 changes: 2 additions & 2 deletions test/Header.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import "@testing-library/jest-dom";
import { render } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import React from 'react';

import { Header } from '../src';

Expand Down
4 changes: 2 additions & 2 deletions test/Hero.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import "@testing-library/jest-dom";
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import React from 'react';
import { Hero, HeroBackground, HeroButton, HeroTitle } from '../src';

describe('Hero component', () => {
Expand Down
6 changes: 3 additions & 3 deletions test/Icon.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import "@testing-library/jest-dom";
import { render, waitFor, within } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import React from 'react';

import { clearIconCache, Icon, preloadIcons, icons } from '../src';
import { readFile } from 'fs/promises';
import { join } from 'path';
import { Icon, clearIconCache, icons, preloadIcons } from '../src';

async function getExceptionList() {
const content = await readFile(join(__dirname, './', 'icons-with-no-title.txt'), 'utf8');
Expand Down
4 changes: 2 additions & 2 deletions test/Input.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import "@testing-library/jest-dom";
import { act, fireEvent, render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import React from 'react';

import { Input, preloadIcons } from '../src';

Expand Down
12 changes: 5 additions & 7 deletions test/Megamenu.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React from 'react';
import "@testing-library/jest-dom";
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import { MegamenuItem, MegamenuFooter, MegamenuHighlightColumn, preloadIcons } from '../src';
import React from 'react';
import { MegamenuFooter, MegamenuHighlightColumn, MegamenuItem, preloadIcons } from '../src';

describe('Megamenu component', () => {
// Icons are now async, so preload them to make it behave in an sync way
beforeAll(() => preloadIcons(['it-list']));
});
// Icons are now async, so preload them to make it behave in an sync way
beforeAll(() => preloadIcons(['it-list']));

describe('MegamenuItem component', () => {
it('should work as container for children elements', () => {
Expand Down
8 changes: 4 additions & 4 deletions test/Notification.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import "@testing-library/jest-dom";
import { act, fireEvent, Matcher, render, screen, waitFor, waitForElementToBeRemoved } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import React from 'react';

import { NotificationId, NotificationManager, notify, preloadIcons } from '../src';

Expand Down Expand Up @@ -170,7 +170,7 @@ describe('Notifications', () => {
expect(onClose).toHaveBeenCalled();
});

describe('local overrides', () => {});
describe('local overrides', () => { });
});

describe('Notification content', () => {
Expand Down Expand Up @@ -219,6 +219,6 @@ describe('Notifications', () => {
await expect(screen.findAllByRole('img')).rejects.toThrowError();
});

it('should apply a state styling and relative icon when set', () => {});
it('should apply a state styling and relative icon when set', () => { });
});
});
6 changes: 3 additions & 3 deletions test/Progress.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import "@testing-library/jest-dom";
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import React from 'react';

import { logError } from '../src/utils';
import { Progress } from '../src';
import { logError } from '../src/utils';

jest.mock('../src/utils', () => ({
logError: jest.fn()
Expand Down
8 changes: 4 additions & 4 deletions test/Rating.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import "@testing-library/jest-dom";
import { fireEvent, render, screen } from '@testing-library/react';
import React from 'react';
import { render, fireEvent, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';

import * as Utils from '../src/utils';
import { isCustomLegendObject } from '../src/Rating/Rating';
import { Rating, preloadIcons } from '../src';
import { isCustomLegendObject } from '../src/Rating/Rating';
import * as Utils from '../src/utils';

jest.mock('./../src/utils', () => {
const utilModule = jest.requireActual('./../src/utils');
Expand Down
4 changes: 2 additions & 2 deletions test/Section.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import "@testing-library/jest-dom";
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import React from 'react';

import { Section } from '../src';
import { muteConsoleWithCheck } from './helper';
Expand Down
4 changes: 2 additions & 2 deletions test/StepperHeaderElement.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import "@testing-library/jest-dom";
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import React from 'react';

import { preloadIcons, StepperHeaderElement } from '../src';

Expand Down
4 changes: 2 additions & 2 deletions test/TextArea.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import "@testing-library/jest-dom";
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import React from 'react';

import { TextArea } from '../src';

Expand Down
4 changes: 2 additions & 2 deletions test/TimelinePin.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import "@testing-library/jest-dom";
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import React from 'react';

import { preloadIcons, TimelinePin } from '../src';

Expand Down
6 changes: 3 additions & 3 deletions test/Toolbar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import "@testing-library/jest-dom";
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import { preloadIcons, Toolbar, ToolbarItem } from '../src';
import React from 'react';
import { Toolbar, ToolbarItem, preloadIcons } from '../src';

describe('Toolbar component', () => {
// Icons are now async, so preload them to make it behave in an sync way
Expand Down
4 changes: 2 additions & 2 deletions test/ToolbarDividerItem.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import "@testing-library/jest-dom";
import { render } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import React from 'react';
import { ToolbarDividerItem } from '../src';

describe('ToolbarDividerItem component', () => {
Expand Down
6 changes: 3 additions & 3 deletions test/ToolbarItem.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { ReactElement } from 'react';
import "@testing-library/jest-dom";
import { fireEvent, render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import { ToolbarItem, preloadIcons, Toolbar } from '../src';
import React, { ReactElement } from 'react';
import { Toolbar, ToolbarItem, preloadIcons } from '../src';

function renderWithSize(size: 'small' | 'medium' | 'large', ui: ReactElement) {
return render(<Toolbar size={size}>{ui}</Toolbar>);
Expand Down

0 comments on commit 5a57a6d

Please sign in to comment.