Skip to content

fix(events): fix firing events in document #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2019

Conversation

tnunes
Copy link
Contributor

@tnunes tnunes commented Mar 12, 2019

What:

Fix firing events in the document element.

Fixes #159, as per @kentcdodds suggestion in #159 (comment).

Why:

Currently firing events in the document element throws a TypeError: Cannot read property 'defaultView' of null when trying to use fireEvent "shortcut API" (not sure this is its name :)):

fireEvent.keyDown(document, { key: 'Escape' })

It was possible to fire events in the document by using fireEvent directly, like so:

fireEvent(document, new KeyboardEvent('keydown', { key: 'Escape' }))

How:

Falling back to node to get defaultView from, when node.ownerDocument is null.

Checklist:

  • Documentation added to the docs site N/A
  • Typescript definitions updated N/A
  • Tests
  • Ready to be merged
  • Added myself to contributors table

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me! Thank you a ton!

@kentcdodds kentcdodds merged commit 7ed2bcb into testing-library:master Mar 12, 2019
@kentcdodds
Copy link
Member

🎉 This PR is included in version 3.17.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@tnunes
Copy link
Contributor Author

tnunes commented Mar 12, 2019

Thanks! When can we expect a new release of react-testing-library with this dependency bumped?

@alexkrolick
Copy link
Collaborator

You should be able to do yarn upgrade react-testing-library to immediately get the new version because of the ^ dependency requirement.

@tnunes
Copy link
Contributor Author

tnunes commented Mar 12, 2019

@alexkrolick you're right! Thanks again for the quick merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants