Skip to content

Commit

Permalink
RAC-225: fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenVAIDIE authored and juliensnz committed Sep 8, 2020
1 parent 895e0b8 commit a8f9600
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
@@ -1,5 +1,5 @@
import React from 'react';
import {fireEvent, render} from '@testing-library/react';
import {fireEvent, render} from '../../shared/test-util';
import {Checkbox} from './Checkbox';

it('it calls onChange handler when user clicks on checkbox', () => {
Expand Down Expand Up @@ -29,5 +29,5 @@ it('it does not call onChange handler when read-only', () => {
it('it cannot be instantiated without handler when not readonly', () => {
expect(() => {
render(<Checkbox checked={true} label="Checkbox"/>);
}).toThrow('A Checkbox element expect a onChange attribute if not readOnly');
}).toThrow('A Checkbox element expect an onChange attribute if not readOnly');
});
18 changes: 18 additions & 0 deletions akeneo-design-system/src/shared/test-util.tsx
@@ -0,0 +1,18 @@
import React, {ComponentType, ReactElement, ReactNode} from 'react';
import {render, RenderOptions} from '@testing-library/react';
import AkeneoPim from '../themes/akeneo-pim';
import { ThemeProvider } from 'styled-components';

const AllTheProviders = ({children}: {children: ReactNode}) => {
return (
<ThemeProvider theme={AkeneoPim}>
{children}
</ThemeProvider>
);
};

const customRender = (ui: ReactElement, options?: Omit<RenderOptions, 'queries'>) =>
render(ui, { wrapper: AllTheProviders as ComponentType, ...options });

export * from '@testing-library/react';
export { customRender as render };

0 comments on commit a8f9600

Please sign in to comment.