Skip to content

Commit

Permalink
Test(web-react): Use Jest's automock functionality to share useIcon m…
Browse files Browse the repository at this point in the history
…ock between tests
  • Loading branch information
literat committed Dec 17, 2024
1 parent 430ffee commit 3fbaddc
Show file tree
Hide file tree
Showing 32 changed files with 48 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import AccordionHeader from '../AccordionHeader';
import AccordionItem from '../AccordionItem';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('AccordionHeader', () => {
classNamePrefixProviderTest(AccordionHeader, 'Accordion__itemHeader');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import Accordion from '../Accordion';
import AccordionContent from '../AccordionContent';
import AccordionHeader from '../AccordionHeader';
import AccordionItem from '../AccordionItem';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('AccordionItem', () => {
classNamePrefixProviderTest(AccordionItem, 'Accordion__item');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import '@testing-library/jest-dom';
import { fireEvent, render } from '@testing-library/react';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import AccordionContent from '../AccordionContent';
import AccordionHeader from '../AccordionHeader';
import AccordionItem from '../AccordionItem';
import UncontrolledAccordion from '../UncontrolledAccordion';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('UncontrolledAccordion', () => {
classNamePrefixProviderTest(UncontrolledAccordion, 'Accordion');
Expand Down
10 changes: 2 additions & 8 deletions packages/web-react/src/components/Alert/__tests__/Alert.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import {
useIconMock,
classNamePrefixProviderTest,
emotionColorPropsTest,
restPropsTest,
stylePropsTest,
} from '@local/tests';
import { classNamePrefixProviderTest, emotionColorPropsTest, restPropsTest, stylePropsTest } from '@local/tests';
import Alert from '../Alert';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('Alert', () => {
classNamePrefixProviderTest(Alert, 'Alert');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import Breadcrumbs from '../Breadcrumbs';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('Breadcrumbs', () => {
classNamePrefixProviderTest(Breadcrumbs, 'Breadcrumbs');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import BreadcrumbsItem from '../BreadcrumbsItem';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('BreadcrumbsItem', () => {
classNamePrefixProviderTest(BreadcrumbsItem, 'd-none');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import {
useIconMock,
classNamePrefixProviderTest,
actionButtonColorPropsTest,
emotionColorPropsTest,
Expand All @@ -13,7 +12,7 @@ import {
} from '@local/tests';
import Button from '../Button';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('Button', () => {
classNamePrefixProviderTest(Button, 'Button');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@local/tests';
import ButtonLink from '../ButtonLink';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('ButtonLink', () => {
classNamePrefixProviderTest(ButtonLink, 'Button');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock, restPropsTest, stylePropsTest } from '@local/tests';
import { restPropsTest, stylePropsTest } from '@local/tests';
import { Button } from '../../Button';
import DropdownTrigger from '../DropdownTrigger';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('DropdownTrigger', () => {
stylePropsTest((props) => <DropdownTrigger elementType={Button} {...props} />);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import '@testing-library/jest-dom';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import FileUploader from '../FileUploader';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('FileUploader', () => {
classNamePrefixProviderTest(FileUploader, 'FileUploader');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { render, screen } from '@testing-library/react';
import React from 'react';
import { renderToString } from 'react-dom/server';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, validationTextPropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, validationTextPropsTest } from '@local/tests';
import FileUploaderInput from '../FileUploaderInput';
import '@testing-library/jest-dom';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('FileUploaderInput', () => {
classNamePrefixProviderTest(FileUploaderInput, 'FileUploaderInput');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { SpiritFileUploaderAttachmentProps } from '../../../types';
import FileUploader from '../FileUploader';
import FileUploaderList from '../FileUploaderList';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('FileUploaderList', () => {
const props = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import HeaderDialogCloseButton from '../HeaderDialogCloseButton';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('HeaderDialogCloseButton', () => {
classNamePrefixProviderTest(HeaderDialogCloseButton, 'HeaderDialogCloseButton');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { HEADER_MENU_TOGGLE_LABEL_DEFAULT } from '../constants';
import HeaderMobileActions from '../HeaderMobileActions';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('HeaderMobileActions', () => {
classNamePrefixProviderTest(HeaderMobileActions, 'HeaderMobileActions');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock, restPropsTest, stylePropsTest } from '@local/tests';
import { restPropsTest, stylePropsTest } from '@local/tests';
import Icon from '../Icon';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('Icon', () => {
const AddIcon = (props: Record<string, unknown>) => <Icon {...props} name="add" data-testid="test-icon" />;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import React from 'react';
import { useIconMock, restPropsTest, stylePropsTest } from '@local/tests';
import { restPropsTest, stylePropsTest } from '@local/tests';
import { SpiritItemProps } from '../../../types';
import Item from '../Item';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('Item', () => {
stylePropsTest(Item);
Expand Down
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 { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import ModalCloseButton from '../ModalCloseButton';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('ModalCloseButton', () => {
classNamePrefixProviderTest(ModalCloseButton, 'Button');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import ModalHeader from '../ModalHeader';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('ModalHeader', () => {
classNamePrefixProviderTest(ModalHeader, 'ModalHeader');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import '@testing-library/jest-dom';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import PaginationButtonLink from '../PaginationButtonLink';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('PaginationButtonLink', () => {
classNamePrefixProviderTest(PaginationButtonLink, 'Button');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import '@testing-library/jest-dom';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import PaginationLinkNext from '../PaginationLinkNext';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('PaginationLinkNext', () => {
classNamePrefixProviderTest(PaginationLinkNext, 'Button');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import '@testing-library/jest-dom';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import PaginationLinkPrevious from '../PaginationLinkPrevious';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('PaginationLinkPrevious', () => {
classNamePrefixProviderTest(PaginationLinkPrevious, 'Button');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import { useIconMock } from '@local/tests';
import UncontrolledPagination from '../UncontrolledPagination';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('UncontrolledPagination', () => {
const onPageChange = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@local/tests';
import Select from '../Select';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('Select', () => {
classNamePrefixProviderTest(Select, 'Select');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '@local/tests';
import Spinner from '../Spinner';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('Spinner', () => {
classNamePrefixProviderTest(Spinner, 'animation-spin-clockwise');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import '@testing-library/jest-dom';
import { fireEvent, render, screen } from '@testing-library/react';
import React from 'react';
import {
useIconMock,
classNamePrefixProviderTest,
validationStatePropsTest,
restPropsTest,
Expand All @@ -12,7 +11,7 @@ import {
import { TextFieldType } from '../../../types';
import TextField from '../TextField';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('TextField', () => {
describe.each(['text', 'password', 'email'])('input type %s', (type) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import React from 'react';
import { useIconMock, classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import { classNamePrefixProviderTest, restPropsTest, stylePropsTest } from '@local/tests';
import ToastBar from '../ToastBar';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('ToastBar', () => {
classNamePrefixProviderTest((props) => <ToastBar {...props} id="test" />, 'ToastBar');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ToastLinkProps } from '../../../types';
import { ToastContext } from '../ToastContext';
import UncontrolledToast from '../UncontrolledToast';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

const defaultToast = {
id: 'test-id',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { Icon } from '../../Icon';
import UNSTABLE_Avatar from '../UNSTABLE_Avatar';

jest.mock('../../../hooks', () => useIconMock);
jest.mock('../../../hooks/useIcon');

describe('UNSTABLE_Avatar', () => {
classNamePrefixProviderTest(UNSTABLE_Avatar, 'UNSTABLE_Avatar');
Expand Down
1 change: 1 addition & 0 deletions packages/web-react/src/hooks/__mocks__/useIcon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const useIcon = jest.fn(() => '');
1 change: 0 additions & 1 deletion packages/web-react/tests/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './providerTests';
export * from './testUtils';
export * from './mocks';
4 changes: 0 additions & 4 deletions packages/web-react/tests/mocks/hooksMock.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/web-react/tests/mocks/index.ts

This file was deleted.

0 comments on commit 3fbaddc

Please sign in to comment.