React-testing-library: onBlur not firing on valid input

Created on 5 Dec 2019  路  5Comments  路  Source: testing-library/react-testing-library

Hello! I've ran into an issue where onBlur handler's are not being fired properly when I try to interact with them using fireEvent and normal actions (like click and tab). If I use fireEvent.focus and fireEvent.blur it works fine, but I'd really prefer testing with the standard events.

I saw what looked like a related issue in #359 but that revolved around the input not having type="text, which I've covered in my use case.

  • react-testing-library version: 9.1.4
  • react version: 16.9

I've created a minimal reproduction case here

https://codesandbox.io/s/onblur-not-working-yv1dv

Most helpful comment

Ah makes sense! @kentcdodds Do you think this would be a candidate to get added to the FAQ or potentially the actions documentation page?

All 5 comments

Could you clarify why the onBlur handler should be called in the second test case when the element isn't blurred?

Yes @msurekci, I believe that's exactly the problem.

I'm afraid there's nothing we can do here. You'll need to fire the blur event manually.

Ah makes sense! @kentcdodds Do you think this would be a candidate to get added to the FAQ or potentially the actions documentation page?

Yes. If you would like to make a pull request to add it I would be grateful!

Was this page helpful?
0 / 5 - 0 ratings