Skip to content

Commit 46deef0

Browse files
SeanKent C. Dodds
Sean
authored and
Kent C. Dodds
committed
docs: remove use of spy to click an event in README.md (#184)
<!-- Thanks for your interest in the project. Bugs filed and PRs submitted are appreciated! Please make sure that you are familiar with and follow the Code of Conduct for this project (found in the CODE_OF_CONDUCT.md file). Also, please make sure you're familiar with and follow the instructions in the contributing guidelines (found in the CONTRIBUTING.md file). If you're new to contributing to open source projects, you might find this free video course helpful: http://kcd.im/pull-request Please fill out the information below to expedite the review and (hopefully) merge of your pull request! --> <!-- What changes are being made? (What feature/bug is being fixed here?) --> **What**: I replaced the spy and MouseEvent bubbling in the README.md <!-- Why are these changes necessary? --> **Why**: Handling clicks in this manner didn't work in my project, while `fireEvent.click(...)` did. Also a global search of this repo show the only instance of this handling occurring in the README.md <!-- How were these changes implemented? --> **How**: <!-- Have you done all of these things? --> **Checklist**: <!-- add "N/A" to the end of each line that's irrelevant to your changes --> <!-- to check an item, place an "x" in the box like so: "- [x] Documentation" --> - [ x] Documentation - [ x] Tests - [ x] Ready to be merged <!-- In your opinion, is this ready to be merged as soon as it's reviewed? --> - [ ] Added myself to contributors table <!-- this is optional, see the contributing guidelines for instructions --> <!-- feel free to add additional comments --> If I'm wrong here, please tell me how. I'm new to open source and would like to learn. If I'm right, this one is such a gimme I feel I should earn a spot as a contributor with a separate task. This library is awesome, keep up the great work!
1 parent dd433c0 commit 46deef0

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

README.md

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ import {render, fireEvent, cleanup, waitForElement} from 'react-testing-library'
8787
// this adds custom jest matchers from jest-dom
8888
import 'jest-dom/extend-expect'
8989

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

9595
// automatically unmount and cleanup DOM after the test is finished.
@@ -275,15 +275,14 @@ module.exports = {
275275
}
276276
```
277277

278-
279278
#### Export Issue with Babel Versions Lower Than 7
280279

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

285284
<details>
286-
<summary>Workaround</summary>
285+
<summary>Workaround</summary>
287286

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

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

298297
module.exports = {
299-
...rtl,
300-
render: customRender,
298+
...rtl,
299+
render: customRender,
301300
}
302301
```
303302

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

610609
test('clicks submit button', () => {
611-
const spy = jest.fn()
612-
const {getByText} = render(<button onClick={spy}>Submit</button>)
613-
614-
fireEvent(
615-
getByText('Submit'),
616-
new MouseEvent('click', {
617-
bubbles: true, // click events must bubble for React to see it
618-
cancelable: true,
619-
}),
620-
)
610+
const {getByText} = render(<button onClick={handleClick}>Submit</button>)
621611

622-
expect(spy).toHaveBeenCalledTimes(1)
612+
fireEvent.click(getByText('Submit'))
623613
})
624614
```
625615

0 commit comments

Comments
 (0)