diff --git a/.all-contributorsrc b/.all-contributorsrc
index 8e42dc90..08a63625 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -507,6 +507,16 @@
"contributions": [
"code"
]
+ },
+ {
+ "login": "tnunes",
+ "name": "Tiago Nunes",
+ "avatar_url": "https://avatars1.githubusercontent.com/u/163187?v=4",
+ "profile": "https://github.com/tnunes",
+ "contributions": [
+ "code",
+ "test"
+ ]
}
]
}
diff --git a/README.md b/README.md
index 643a2103..aae15d6f 100644
--- a/README.md
+++ b/README.md
@@ -138,7 +138,7 @@ Thanks goes to these people ([emoji key][emojis]):
| [
dadamssg](https://github.com/dadamssg)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=dadamssg "Code") | [
Neil Kistner](https://neilkistner.com/)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=wyze "Code") | [
Ben Chauvette](http://bdchauvette.net/)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=bdchauvette "Code") | [
Jeff Baumgardt](https://github.com/JeffBaumgardt)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=JeffBaumgardt "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=JeffBaumgardt "Documentation") | [
Matan Kushner](http://matchai.me)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=matchai "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=matchai "Documentation") [🤔](#ideas-matchai "Ideas, Planning, & Feedback") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=matchai "Tests") | [
Alex Wendte](http://www.wendtedesigns.com/)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=themostcolm "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=themostcolm "Documentation") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=themostcolm "Tests") | [
Tamas Fodor](https://github.com/ruffle1986)
[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=ruffle1986 "Documentation") |
| [
Benjamin Eckardt](https://github.com/BenjaminEckardt)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=BenjaminEckardt "Code") | [
Ryan Campbell](https://github.com/campbellr)
[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=campbellr "Documentation") | [
Taylor Briggs](https://taylor-briggs.com)
[⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=TaylorBriggs "Tests") | [
John Gozde](https://github.com/jgoz)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=jgoz "Code") | [
C. T. Lin](https://github.com/chentsulin)
[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=chentsulin "Documentation") | [
Terrence Wong](http://terrencewwong.com)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=terrencewwong "Code") | [
Soo Jae Hwang](https://www.ossfinder.com)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=misoguy "Code") |
| [
Royston Shufflebotham](https://github.com/RoystonS)
[🐛](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3ARoystonS "Bug reports") [💻](https://github.com/kentcdodds/dom-testing-library/commits?author=RoystonS "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=RoystonS "Documentation") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=RoystonS "Tests") | [
Vadim Brodsky](http://www.vadimbrodsky.com)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=VadimBrodsky "Code") | [
Eunjae Lee](https://twitter.com/eunjae_lee)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=eunjae-lee "Code") | [
David Peter](http://davidpeter.me)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=sarenji "Code") | [
Shy Alter](https://twitter.com/@puemos)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=puemos "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=puemos "Documentation") | [
Łukasz Makuch](https://lukaszmakuch.pl)
[📦](#platform-lukaszmakuch "Packaging/porting to new platform") | [
Tyler Haas](https://github.com/tylerthehaas)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=tylerthehaas "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=tylerthehaas "Tests") |
-| [
Vesa Laakso](http://vesalaakso.com)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=valscion "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=valscion "Tests") | [
Tulsi Sapkota](https://github.com/Tolsee)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=Tolsee "Code") |
+| [
Vesa Laakso](http://vesalaakso.com)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=valscion "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=valscion "Tests") | [
Tulsi Sapkota](https://github.com/Tolsee)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=Tolsee "Code") | [
Tiago Nunes](https://github.com/tnunes)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=tnunes "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=tnunes "Tests") |
diff --git a/src/__tests__/events.js b/src/__tests__/events.js
index 198ceba0..969a5584 100644
--- a/src/__tests__/events.js
+++ b/src/__tests__/events.js
@@ -185,3 +185,11 @@ test('fires events on Window', () => {
expect(messageSpy).toHaveBeenCalledTimes(1)
window.removeEventListener('message', messageSpy)
})
+
+test('fires events on Document', () => {
+ const keyDownSpy = jest.fn()
+ document.addEventListener('keydown', keyDownSpy)
+ fireEvent.keyDown(document, {key: 'Escape'})
+ expect(keyDownSpy).toHaveBeenCalledTimes(1)
+ document.removeEventListener('keydown', keyDownSpy)
+})
diff --git a/src/events.js b/src/events.js
index 8eeac9eb..af9681e7 100644
--- a/src/events.js
+++ b/src/events.js
@@ -329,7 +329,8 @@ Object.keys(eventMap).forEach(key => {
value: files,
})
}
- const window = node.ownerDocument.defaultView
+ // if the node does not have an owner document, then it probably _is_ the owner document
+ const window = (node.ownerDocument || node).defaultView
const EventConstructor = window[EventType] || window.Event
const event = new EventConstructor(eventName, eventInit)
return fireEvent(node, event)