Skip to content

Commit 6f898a9

Browse files
vitalysoKent C. Dodds
authored and
Kent C. Dodds
committed
fix(events): remove Simulate from dependencies (#210)
* WIP: add setNativeValue for change event * Quick solution for #206 * Add @sivkoff to the contributors table * Use `dom-testing-library` for synthetic event dispatchers * Rollback unnecessary test changes * Update index.js
1 parent c96cd4e commit 6f898a9

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,15 @@
558558
"contributions": [
559559
"doc"
560560
]
561+
},
562+
{
563+
"login": "sivkoff",
564+
"name": "Vitaly Sivkov",
565+
"avatar_url": "https://avatars1.githubusercontent.com/u/2699953?v=4",
566+
"profile": "http://sivkoff.com",
567+
"contributions": [
568+
"code"
569+
]
561570
}
562571
]
563572
}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[![version][version-badge]][package] [![downloads][downloads-badge]][npmtrends]
1616
[![MIT License][license-badge]][license]
1717

18-
[![All Contributors](https://img.shields.io/badge/all_contributors-57-orange.svg?style=flat-square)](#contributors)
18+
[![All Contributors](https://img.shields.io/badge/all_contributors-58-orange.svg?style=flat-square)](#contributors)
1919
[![PRs Welcome][prs-badge]][prs] [![Code of Conduct][coc-badge]][coc]
2020
[![Join the community on Spectrum][spectrum-badge]][spectrum]
2121

@@ -1308,6 +1308,7 @@ Thanks goes to these people ([emoji key][emojis]):
13081308
| [<img src="https://avatars3.githubusercontent.com/u/881986?v=4" width="100px;"/><br /><sub><b>dadamssg</b></sub>](https://github.com/dadamssg)<br />[📖](https://github.com/kentcdodds/react-testing-library/commits?author=dadamssg "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/8734097?v=4" width="100px;"/><br /><sub><b>Yazan Aabed</b></sub>](https://www.yaabed.com/)<br />[📝](#blog-YazanAabeed "Blogposts") | [<img src="https://avatars0.githubusercontent.com/u/556258?v=4" width="100px;"/><br /><sub><b>Tim</b></sub>](https://github.com/timbonicus)<br />[🐛](https://github.com/kentcdodds/react-testing-library/issues?q=author%3Atimbonicus "Bug reports") [💻](https://github.com/kentcdodds/react-testing-library/commits?author=timbonicus "Code") [📖](https://github.com/kentcdodds/react-testing-library/commits?author=timbonicus "Documentation") [⚠️](https://github.com/kentcdodds/react-testing-library/commits?author=timbonicus "Tests") | [<img src="https://avatars3.githubusercontent.com/u/6682655?v=4" width="100px;"/><br /><sub><b>Divyanshu Maithani</b></sub>](http://divyanshu.xyz)<br />[✅](#tutorial-divyanshu013 "Tutorials") [📹](#video-divyanshu013 "Videos") | [<img src="https://avatars2.githubusercontent.com/u/9116042?v=4" width="100px;"/><br /><sub><b>Deepak Grover</b></sub>](https://www.linkedin.com/in/metagrover)<br />[✅](#tutorial-metagrover "Tutorials") [📹](#video-metagrover "Videos") | [<img src="https://avatars0.githubusercontent.com/u/16276358?v=4" width="100px;"/><br /><sub><b>Eyal Cohen</b></sub>](https://github.com/eyalcohen4)<br />[📖](https://github.com/kentcdodds/react-testing-library/commits?author=eyalcohen4 "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/7452681?v=4" width="100px;"/><br /><sub><b>Peter Makowski</b></sub>](https://github.com/petermakowski)<br />[📖](https://github.com/kentcdodds/react-testing-library/commits?author=petermakowski "Documentation") |
13091309
| [<img src="https://avatars2.githubusercontent.com/u/20361668?v=4" width="100px;"/><br /><sub><b>Michiel Nuyts</b></sub>](https://github.com/Michielnuyts)<br />[📖](https://github.com/kentcdodds/react-testing-library/commits?author=Michielnuyts "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/1195863?v=4" width="100px;"/><br /><sub><b>Joe Ng'ethe</b></sub>](https://github.com/joeynimu)<br />[💻](https://github.com/kentcdodds/react-testing-library/commits?author=joeynimu "Code") [📖](https://github.com/kentcdodds/react-testing-library/commits?author=joeynimu "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/19998290?v=4" width="100px;"/><br /><sub><b>Kate</b></sub>](https://github.com/Enikol)<br />[📖](https://github.com/kentcdodds/react-testing-library/commits?author=Enikol "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/11980217?v=4" width="100px;"/><br /><sub><b>Sean</b></sub>](http://www.seanrparker.com)<br />[📖](https://github.com/kentcdodds/react-testing-library/commits?author=SeanRParker "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/17031?v=4" width="100px;"/><br /><sub><b>James Long</b></sub>](http://jlongster.com)<br />[🤔](#ideas-jlongster "Ideas, Planning, & Feedback") [📦](#platform-jlongster "Packaging/porting to new platform") | [<img src="https://avatars1.githubusercontent.com/u/10118777?v=4" width="100px;"/><br /><sub><b>Herb Hagely</b></sub>](https://github.com/hhagely)<br />[💡](#example-hhagely "Examples") | [<img src="https://avatars2.githubusercontent.com/u/5779538?v=4" width="100px;"/><br /><sub><b>Alex Wendte</b></sub>](http://www.wendtedesigns.com/)<br />[💡](#example-themostcolm "Examples") |
13101310
| [<img src="https://avatars0.githubusercontent.com/u/6998954?v=4" width="100px;"/><br /><sub><b>Monica Powell</b></sub>](http://www.aboutmonica.com)<br />[📖](https://github.com/kentcdodds/react-testing-library/commits?author=M0nica "Documentation") |
1311+
| [<img src="https://avatars1.githubusercontent.com/u/2699953?v=4" width="100px;"/><br /><sub><b>Vitaly Sivkov</b></sub>](http://sivkoff.com)<br />[💻](https://github.com/kentcdodds/react-testing-library/commits?author=sivkoff "Code") |
13111312
13121313
<!-- ALL-CONTRIBUTORS-LIST:END -->
13131314

src/index.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import ReactDOM from 'react-dom'
2-
import {Simulate} from 'react-dom/test-utils'
3-
import {getQueriesForElement, prettyDOM} from 'dom-testing-library'
2+
import {getQueriesForElement, prettyDOM, fireEvent} from 'dom-testing-library'
43

54
const mountedContainers = new Set()
65

@@ -59,14 +58,29 @@ function cleanupAtContainer(container) {
5958
mountedContainers.delete(container)
6059
}
6160

62-
// fallback to synthetic events for React events that the DOM doesn't support
63-
const syntheticEvents = ['select', 'mouseEnter', 'mouseLeave']
64-
syntheticEvents.forEach(eventName => {
65-
document.addEventListener(eventName.toLowerCase(), e => {
66-
Simulate[eventName](e.target, e)
67-
})
68-
})
61+
// React event system tracks native mouseOver/mouseOut events for
62+
// running onMouseEnter/onMouseLeave handlers
63+
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/EnterLeaveEventPlugin.js#L24-L31
64+
fireEvent.mouseEnter = fireEvent.mouseOver
65+
fireEvent.mouseLeave = fireEvent.mouseOut
66+
67+
fireEvent.select = (node, init) => {
68+
// React tracks this event only on focused inputs
69+
node.focus()
70+
71+
// React creates this event when one of the following native events happens
72+
// - contextMenu
73+
// - mouseUp
74+
// - dragEnd
75+
// - keyUp
76+
// - keyDown
77+
// so we can use any here
78+
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/SelectEventPlugin.js#L203-L224
79+
fireEvent.keyUp(node, init)
80+
}
6981

7082
// just re-export everything from dom-testing-library
7183
export * from 'dom-testing-library'
7284
export {render, cleanup}
85+
86+
/* eslint func-name-matching:0 */

0 commit comments

Comments
 (0)