score:3

sunk several hours in to this today. from what i can see, react native testing library doesn't have this matcher and neither does the jest native matcher extender.

it looks like detox supports it though.

there are lots of suggestions to use refs (which might let us call ref.current.isfocused()), or capture onfocus\onblur events. but these aren't viable from the test environment perspective.

there were 2 things i observed with the refs.

  1. the refs all get mocked out in jest (i don't know enough about jest to know why).
  2. when the element is not focused, the ref is completely gone

regarding, tracking onfocus\onblur, it's unnecessary overhead and only further complicates the production code for the sake of testing. then the component has to accept these as props and a mock has to be created for each one... no thanks!

i decided to open a feature request in the jest native project. cross your fingers.

react.js users have it so easy!


Related Query

More Query from same tag