Skip to content

removing use of spy to click an event in README.md #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ import {render, fireEvent, cleanup, waitForElement} from 'react-testing-library'
// this adds custom jest matchers from jest-dom
import 'jest-dom/extend-expect'

// the mock lives in a __mocks__ directory
// the mock lives in a __mocks__ directory
// to know more about manual mocks, access: https://jestjs.io/docs/en/manual-mocks
import axiosMock from 'axios'
import axiosMock from 'axios'
import Fetch from '../fetch' // see the tests for a full implementation

// automatically unmount and cleanup DOM after the test is finished.
Expand Down Expand Up @@ -275,15 +275,14 @@ module.exports = {
}
```


#### Export Issue with Babel Versions Lower Than 7

Babel versions lower than 7 throw an error when trying to override the named export
in the example above. (See
Babel versions lower than 7 throw an error when trying to override the named
export in the example above. (See
[#169](https://github.com/kentcdodds/react-testing-library/issues/169).)

<details>
<summary>Workaround</summary>
<summary>Workaround</summary>

You can use CommonJS modules instead of ES modules, which should work in Node:

Expand All @@ -296,8 +295,8 @@ const customRender = (node, ...options) => {
}

module.exports = {
...rtl,
render: customRender,
...rtl,
render: customRender,
}
```

Expand Down Expand Up @@ -608,18 +607,9 @@ import {render, cleanup, fireEvent} from 'react-testing-library'
afterEach(cleanup)

test('clicks submit button', () => {
const spy = jest.fn()
const {getByText} = render(<button onClick={spy}>Submit</button>)

fireEvent(
getByText('Submit'),
new MouseEvent('click', {
bubbles: true, // click events must bubble for React to see it
cancelable: true,
}),
)
const {getByText} = render(<button onClick={handleClick}>Submit</button>)

expect(spy).toHaveBeenCalledTimes(1)
fireEvent.click(getByText('Submit'))
})
```

Expand Down