Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit will setup the test environment using react-testing-library
which will help us to test components. - Added prettier to devDependencies so we don't need to have it installed on our machines for the lint-staged to run without crashing. - Added the test script to husky - Added some test examples to the confirm_dialog - Added prop-types to validate components props.
- Loading branch information
Carlos Junior
committed
Mar 31, 2020
1 parent
15300ed
commit c14f403
Showing
7 changed files
with
276 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/package/components/commons/confirm_dialog/confirm_dialog.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import { ThemeProvider } from 'react-jss'; | ||
import { IntlProvider } from 'react-intl'; | ||
|
||
import en from '../../../i18n/en.json'; | ||
import { buildTheme } from '../../../utils/styles/theme/theme'; | ||
|
||
import { ConfirmDialog } from './confirm_dialog'; | ||
|
||
const Providers = ({ children }) => ( | ||
<ThemeProvider theme={buildTheme()}> | ||
<IntlProvider locale="en" defaultLocale="en" messages={en}> | ||
{children} | ||
</IntlProvider> | ||
</ThemeProvider> | ||
); | ||
|
||
describe('<ConfirmDialog />', () => { | ||
it('should render with the default title', () => { | ||
const screen = render( | ||
<Providers> | ||
<ConfirmDialog open /> | ||
</Providers> | ||
); | ||
|
||
expect(screen.getByText('Are you sure?')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call the onClose function when click close', () => { | ||
const onClose = jest.fn(); | ||
const screen = render( | ||
<Providers> | ||
<ConfirmDialog open onClose={onClose} /> | ||
</Providers> | ||
); | ||
|
||
fireEvent.click(screen.getByText('Close')); | ||
|
||
expect(onClose).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import '@testing-library/jest-dom/extend-expect'; |
Oops, something went wrong.