issue: setFocus is not working with @testing-library/react-native #11458
Replies: 2 comments 1 reply
-
hook form will call ref.focus(), if it's not been register correctly then it won't work. |
Beta Was this translation helpful? Give feedback.
-
I can confirm this is happening. Tested with Jest, React Testing Library and React Hook Forms. I can check if it's selected (shouldSelect: true) with the matches below. Since it's React Hook Forms that is doing that, I'll just believe it's enough but I also think it should pass regardless. Something is getting in the way of this. // won't work
expect(theInput).toHaveFocus();
// works
expect((theInput as HTMLInputElement).selectionStart).toBe(0);
expect((theInput as HTMLInputElement).selectionEnd).toBe(code.length); If I had to guess, I think the form is resetted after submitting and it's causing the button type="button" to be focused again, only in node. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Version Number
7.49.3
Codesandbox/Expo snack
facing issue on Expo Snack : jest installation fialed.
Steps to reproduce
Component
Test Case
Expected behaviour
setFocus will focus on input.
In above example,
onFocus={() => console.log('Focused')}
should be called. when testingawait event.press(btnWrapper)
What browsers are you seeing the problem on?
No response
Relevant log output
The test is passed without focusing on the input.
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions