diff --git a/.all-contributorsrc b/.all-contributorsrc index fc50632f..5e2bca49 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -431,6 +431,15 @@ "doc", "test" ] + }, + { + "login": "VadimBrodsky", + "name": "Vadim Brodsky", + "avatar_url": "https://avatars0.githubusercontent.com/u/591673?v=4", + "profile": "http://www.vadimbrodsky.com", + "contributions": [ + "code" + ] } ] } diff --git a/README.md b/README.md index 65625191..fd22e28a 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ [![downloads][downloads-badge]][npmtrends] [![MIT License][license-badge]][license] -[![All Contributors](https://img.shields.io/badge/all_contributors-43-orange.svg?style=flat-square)](#contributors) +[![All Contributors](https://img.shields.io/badge/all_contributors-44-orange.svg?style=flat-square)](#contributors) [![PRs Welcome][prs-badge]][prs] [![Code of Conduct][coc-badge]][coc] @@ -1142,7 +1142,7 @@ Thanks goes to these people ([emoji key][emojis]): | [
Jonathan Stoye](http://jonathanstoye.de)
[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=JonathanStoye "Documentation") | [
Sanghyeon Lee](https://github.com/yongdamsh)
[💡](#example-yongdamsh "Examples") | [
Justice Mba ](https://github.com/Dajust)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=Dajust "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=Dajust "Documentation") [🤔](#ideas-Dajust "Ideas, Planning, & Feedback") | [
Wayne Crouch](https://github.com/wgcrouch)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=wgcrouch "Code") | [
Ben Elliott](http://benjaminelliott.co.uk)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=benelliott "Code") | [
Ruben Costa](http://nuances.co)
[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=rubencosta "Code") | [
Robert Smith](http://rbrtsmith.com/)
[🐛](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3Arbrtsmith "Bug reports") [🤔](#ideas-rbrtsmith "Ideas, Planning, & Feedback") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=rbrtsmith "Documentation") | | [
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") | +| [
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") | diff --git a/src/__tests__/events.js b/src/__tests__/events.js index 10b15f69..2743ff39 100644 --- a/src/__tests__/events.js +++ b/src/__tests__/events.js @@ -1,5 +1,6 @@ import {fireEvent} from '..' import document from './helpers/document' +import window from './helpers/window' const eventTypes = [ { @@ -178,3 +179,11 @@ test('assigning the files property on an input', () => { fireEvent.change(node, {target: {files: [file]}}) expect(node.files).toEqual([file]) }) + +test('fires events on Window', () => { + const messageSpy = jest.fn() + window.addEventListener('message', messageSpy) + fireEvent(window, new window.MessageEvent('message', {data: 'hello'})) + expect(messageSpy).toHaveBeenCalledTimes(1) + window.removeEventListener('message', messageSpy) +}) diff --git a/src/__tests__/helpers/window.js b/src/__tests__/helpers/window.js new file mode 100644 index 00000000..f9ebb36c --- /dev/null +++ b/src/__tests__/helpers/window.js @@ -0,0 +1,9 @@ +let testWindow = typeof window === 'undefined' ? undefined : window + +if (typeof window === 'undefined') { + const {JSDOM} = require('jsdom') + const dom = new JSDOM() + testWindow = dom.window +} + +module.exports = testWindow diff --git a/typings/events.d.ts b/typings/events.d.ts index c24f852b..103bc0cd 100644 --- a/typings/events.d.ts +++ b/typings/events.d.ts @@ -69,9 +69,9 @@ export type EventType = | 'transitionEnd' | 'doubleClick' -export type FireFunction = (element: Element, event: Event) => boolean +export type FireFunction = (element: Element | Window, event: Event) => boolean export type FireObject = { - [K in EventType]: (element: Element, options?: {}) => boolean + [K in EventType]: (element: Element | Window, options?: {}) => boolean } export const fireEvent: FireFunction & FireObject