diff --git a/.all-contributorsrc b/.all-contributorsrc
index db2f5738..2d2e9190 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -558,6 +558,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "sivkoff",
+ "name": "Vitaly Sivkov",
+ "avatar_url": "https://avatars1.githubusercontent.com/u/2699953?v=4",
+ "profile": "http://sivkoff.com",
+ "contributions": [
+ "code"
+ ]
}
]
}
diff --git a/README.md b/README.md
index 9992e8a0..1f498fb3 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@
[![version][version-badge]][package] [![downloads][downloads-badge]][npmtrends]
[![MIT License][license-badge]][license]
-[](#contributors)
+[](#contributors)
[![PRs Welcome][prs-badge]][prs] [![Code of Conduct][coc-badge]][coc]
[![Join the community on Spectrum][spectrum-badge]][spectrum]
@@ -1308,6 +1308,7 @@ Thanks goes to these people ([emoji key][emojis]):
| [
dadamssg](https://github.com/dadamssg)
[📖](https://github.com/kentcdodds/react-testing-library/commits?author=dadamssg "Documentation") | [
Yazan Aabed](https://www.yaabed.com/)
[📝](#blog-YazanAabeed "Blogposts") | [
Tim](https://github.com/timbonicus)
[🐛](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") | [
Divyanshu Maithani](http://divyanshu.xyz)
[✅](#tutorial-divyanshu013 "Tutorials") [📹](#video-divyanshu013 "Videos") | [
Deepak Grover](https://www.linkedin.com/in/metagrover)
[✅](#tutorial-metagrover "Tutorials") [📹](#video-metagrover "Videos") | [
Eyal Cohen](https://github.com/eyalcohen4)
[📖](https://github.com/kentcdodds/react-testing-library/commits?author=eyalcohen4 "Documentation") | [
Peter Makowski](https://github.com/petermakowski)
[📖](https://github.com/kentcdodds/react-testing-library/commits?author=petermakowski "Documentation") |
| [
Michiel Nuyts](https://github.com/Michielnuyts)
[📖](https://github.com/kentcdodds/react-testing-library/commits?author=Michielnuyts "Documentation") | [
Joe Ng'ethe](https://github.com/joeynimu)
[💻](https://github.com/kentcdodds/react-testing-library/commits?author=joeynimu "Code") [📖](https://github.com/kentcdodds/react-testing-library/commits?author=joeynimu "Documentation") | [
Kate](https://github.com/Enikol)
[📖](https://github.com/kentcdodds/react-testing-library/commits?author=Enikol "Documentation") | [
Sean](http://www.seanrparker.com)
[📖](https://github.com/kentcdodds/react-testing-library/commits?author=SeanRParker "Documentation") | [
James Long](http://jlongster.com)
[🤔](#ideas-jlongster "Ideas, Planning, & Feedback") [📦](#platform-jlongster "Packaging/porting to new platform") | [
Herb Hagely](https://github.com/hhagely)
[💡](#example-hhagely "Examples") | [
Alex Wendte](http://www.wendtedesigns.com/)
[💡](#example-themostcolm "Examples") |
| [
Monica Powell](http://www.aboutmonica.com)
[📖](https://github.com/kentcdodds/react-testing-library/commits?author=M0nica "Documentation") |
+| [
Vitaly Sivkov](http://sivkoff.com)
[💻](https://github.com/kentcdodds/react-testing-library/commits?author=sivkoff "Code") |
diff --git a/src/index.js b/src/index.js
index 952d7d86..a9db403f 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,6 +1,5 @@
import ReactDOM from 'react-dom'
-import {Simulate} from 'react-dom/test-utils'
-import {getQueriesForElement, prettyDOM} from 'dom-testing-library'
+import {getQueriesForElement, prettyDOM, fireEvent} from 'dom-testing-library'
const mountedContainers = new Set()
@@ -59,14 +58,29 @@ function cleanupAtContainer(container) {
mountedContainers.delete(container)
}
-// fallback to synthetic events for React events that the DOM doesn't support
-const syntheticEvents = ['select', 'mouseEnter', 'mouseLeave']
-syntheticEvents.forEach(eventName => {
- document.addEventListener(eventName.toLowerCase(), e => {
- Simulate[eventName](e.target, e)
- })
-})
+// React event system tracks native mouseOver/mouseOut events for
+// running onMouseEnter/onMouseLeave handlers
+// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/EnterLeaveEventPlugin.js#L24-L31
+fireEvent.mouseEnter = fireEvent.mouseOver
+fireEvent.mouseLeave = fireEvent.mouseOut
+
+fireEvent.select = (node, init) => {
+ // React tracks this event only on focused inputs
+ node.focus()
+
+ // React creates this event when one of the following native events happens
+ // - contextMenu
+ // - mouseUp
+ // - dragEnd
+ // - keyUp
+ // - keyDown
+ // so we can use any here
+ // @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/SelectEventPlugin.js#L203-L224
+ fireEvent.keyUp(node, init)
+}
// just re-export everything from dom-testing-library
export * from 'dom-testing-library'
export {render, cleanup}
+
+/* eslint func-name-matching:0 */