Skip to content
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

Add createEvent that returns the created Event #258

Merged
merged 3 commits into from May 12, 2019

Conversation

Projects
None yet
2 participants
@dbismut
Copy link
Contributor

commented May 12, 2019

What:

Exposes a utility to create events that can be thrown by fireEvent. This is useful in order to have access to the source event attributes see #257

Why:

Some components might rely on event attributes created when the event object is created (i.e. new Event({...eventAttributes})).

How:

As suggested by @kentcdodds in #257:

import {createEvent} from 'dom-testing-library'

const myEvent = createEvent.click(node, eventAttributes)
fireEvent(node, myEvent)

However since the event constructor depends on window which itself depends on the node, createEvent also requires the node to be passed as an argument (not very elegant I admit).

Checklist:

  • Documentation added to the docs site
  • Typescript definitions updated
  • Tests: since fireEvent now uses createEvent I believe successful tests on fireEvent cover createEvent
  • Ready to be merged

Pre-commit hook threw an error on Typescript definitions but I'm really not sure what's wrong, so I committed with the --no-verify flag.

@kentcdodds
Copy link
Member

left a comment

Looks good to me other than one comment

@@ -30,7 +30,8 @@
"test:update": "npm test -- --updateSnapshot --coverage",
"validate": "kcd-scripts validate",
"setup": "npm install && npm run validate -s",
"dtslint": "dtslint typings"
"dtslint": "dtslint typings",
"precommit": "kcd-scripts pre-commit"

This comment has been minimized.

Copy link
@kentcdodds

kentcdodds May 12, 2019

Member

Could you revert these changes?

This comment has been minimized.

Copy link
@dbismut

dbismut May 12, 2019

Author Contributor

Humpf sorry. I was trying to see what was wrong with my commit on typescript definitions...

@kentcdodds
Copy link
Member

left a comment

Excellent 💯

@kentcdodds kentcdodds merged commit 0e7d99e into testing-library:master May 12, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@kentcdodds

This comment has been minimized.

Copy link
Member

commented May 12, 2019

Could you make a pull request to the docs site to add documentation?

@kentcdodds

This comment has been minimized.

Copy link
Member

commented May 12, 2019

@allcontributors[bot] please add @dbismut for code

@allcontributors

This comment has been minimized.

Copy link
Contributor

commented May 12, 2019

@kentcdodds

I've put up a pull request to add @dbismut! 🎉

@kentcdodds

This comment has been minimized.

Copy link
Member

commented May 12, 2019

🎉 This PR is included in version 4.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@kentcdodds kentcdodds added the released label May 12, 2019

@dbismut

This comment has been minimized.

Copy link
Contributor Author

commented May 12, 2019

Yes I will PR the docs (although my English might be shaky)! Is it necessary to add createEvent as an export to react-testing-library?

@kentcdodds

This comment has been minimized.

Copy link
Member

commented May 12, 2019

react-testing-library re-experts everything from dom-testing-library so we're good there 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.