jest-native
jest-native copied to clipboard
feat: toBeFocused
Describe the feature you'd like:
A new matcher for testing if an element is focused.
Similar to what Detox has: https://wix.github.io/Detox/docs/api/expect#tobefocused
this would be really useful!
have no idea why react-testing-library has a focus feature but not react-native-testing-library
Interesting idea. I'm not sure if feasible, as RNTL does it's renders using React Test Renderer and not React Native renderer, and hence it's runtime environment is quite limited. In contract RTL uses real React DOM renderer working with Js DOM to have full-blown browser environment.
@chris-chapin would you be willing to build a PR for this?
Closing as stale.
@chris-chapin if you find any suitable solution to the native/JS issue I've described above feel free to submit a PR for this.
Hello,
In one of our test, the onFocus is setting the focus in a state and then display a list of clickable choice. I am not able to test it because this feature is not supported.
Can we reopen this please?
@kopax-polyconseil afaik supporting toBeFocused()
in Jest Native/React Native Testing Library/React Test Renderer is not possible due to lack of runtime environment that would manage the focus. Original (web) React Testing Library has jsdom to simulate browser env, while Detox runs using real React Native environment on device/emulator.
In our case someone would have to create such non-standard environment, moreover it would have to be maintained to match changes in React Native.
not ideal but its something at least, I ended up wrapping my input with a view with a conditional test_id to search for in my tests
<View testID={`${testID}_${isFocus ? 'focused' : 'not_focused' }>...
not ideal but its something at least, I ended up wrapping my input with a view with a conditional test_id to search for in my tests
<View testID={`${testID}_${isFocus ? 'focused' : 'not_focused' }>...
This makes me so sad that we have to do this.