Skip to content

Add createEvent that returns the created Event #258

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 3 commits into from
May 12, 2019
Merged

Add createEvent that returns the created Event #258

merged 3 commits into from
May 12, 2019

Conversation

dbismut
Copy link
Contributor

@dbismut dbismut 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.

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.

Looks good to me other than one comment

package.json Outdated
@@ -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"
Copy link
Member

Choose a reason for hiding this comment

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

Could you revert these changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

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.

Excellent 💯

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

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

@kentcdodds
Copy link
Member

@allcontributors[bot] please add @dbismut for code

@allcontributors
Copy link
Contributor

@kentcdodds

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

@kentcdodds
Copy link
Member

🎉 This PR is included in version 4.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@dbismut
Copy link
Contributor Author

dbismut 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
Copy link
Member

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
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants