-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test): Switch to @testing-library/react (#73)
Want to switch over from `enzyme` to `@testing-library/react` for testing React components. - Removed `enzyme` (and related packages) - Added [`@testing-library/react`](https://testing-library.com/docs/react-testing-library/intro) (and related packages) - Upgraded `jest`, `@types/jest` & `babel-jest` - Including [`@testing-library/jest-dom/extend-expect`](https://github.com/testing-library/jest-dom) in jest spec setup to get additional `expect()` matchers BREAKING CHANGE: `enzyme` is no longer supported for React component testing
- Loading branch information
Showing
8 changed files
with
3,074 additions
and
1,075 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,24 @@ | ||
import React from 'react' | ||
import { mount } from 'enzyme' | ||
import { act } from 'react-dom/test-utils' | ||
import { render, fireEvent } from '@testing-library/react' | ||
|
||
import Counter from '../Counter' | ||
import Button from '../Button' | ||
|
||
test('starts off at 0 by default', () => { | ||
const counter = mount(<Counter />) | ||
const { queryByText } = render(<Counter />) | ||
|
||
expect(counter).toIncludeText('You clicked 0 times') | ||
expect(queryByText('You clicked 0 times')).toBeInTheDocument() | ||
}) | ||
|
||
test('can have a different initial value', () => { | ||
const counter = mount(<Counter initialCount={14} />) | ||
const { queryByText } = render(<Counter initialCount={14} />) | ||
|
||
expect(counter).toIncludeText('You clicked 14 times') | ||
expect(queryByText('You clicked 14 times')).toBeInTheDocument() | ||
}) | ||
|
||
test('updates count when Button is clicked', () => { | ||
const counter = mount(<Counter initialCount={5} />) | ||
const button = counter.find(Button) | ||
const buttonOnClick = button.prop('onClick') | ||
|
||
if (buttonOnClick) { | ||
// simulate clicking the button by trigger onClick prop of <Button /> | ||
act(() => { | ||
buttonOnClick() | ||
}) | ||
} | ||
|
||
expect(counter).toIncludeText('You clicked 6 times') | ||
const { queryByText, getByText } = render(<Counter initialCount={5} />) | ||
|
||
fireEvent.click(getByText('Click me')) | ||
|
||
expect(queryByText('You clicked 6 times')).toBeInTheDocument() | ||
}) |
Oops, something went wrong.