Skip to content

not.toHaveFocus expects element to have focus #394

Answered by gnapse
jamestrew asked this question in Q&A
Discussion options

You must be logged in to vote

The input has autoFocus enabled, so it is understandable that it has focus. Can you try without autoFocus to see if it works?

Though I'd add this: even though fireEvent.click(codeInput) is too low level and won't actually set focus on the input, in real life if you click on the input element, that'll also set focus on the input. So the situation you're describing in your test has multiple angles through which the input should end up having focus. I wonder why you so adamantly expect it not to have focus. 🤔

And last but not least, I suggest you use userEvent.click(codeInput) instead of fireEvent.click(codeInput). It's on a separate library though. Check it out: https://github.com/testing-l…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jamestrew
Comment options

Answer selected by jamestrew
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #393 on August 19, 2021 14:20.