Skip to content

Provide humane error messages for missing fireEvent() params #355

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
Sep 20, 2019

Conversation

dominykas
Copy link
Contributor

@dominykas dominykas commented Sep 20, 2019

What:

Adds specific error message text when element / node / event params are missing for fireEvent()

Why:

In some cases you may be calling fireEvent without giving it an element, e.g.
while it is discouraged, in some cases it is necessary to use querySelector or similar or you might be accessing a results[0] in an empty array returned by queryAllBy*.

When you do that - fireEvent() will throw the good old Cannot convert undefined or null to object, which means you need to go and look for what exactly happened.

Providing a human readable, specific error message makes it easier to debug such failures.

How:

Throw a specific error after testing a condition.

Checklist:

  • Documentation added to the
    docs site
  • Typescript definitions updated
  • Tests
  • Ready to be merged

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.

Cool. Thank you :)

@kentcdodds kentcdodds merged commit d58cf8d into testing-library:master Sep 20, 2019
@kentcdodds
Copy link
Member

@all-contributors please add @dominykas for code and tests

@allcontributors
Copy link
Contributor

@kentcdodds

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

@kentcdodds
Copy link
Member

🎉 This PR is included in version 6.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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