Simply test case: Want to see if a given element is focused.
To check if an element is focused on a react web app with RTL and jest, you have two easy options available to you:
- You can check if the element is the same as document.activeElement (may have to discard some wrappers)
- You can extend your jest matchers with https://github.com/testing-library/jest-dom#tohavefocus and use
expect(<element>).toHaveFocus()
I'm not sure what the equivalent check would be with react native (the RN equivalent to the jest-dom extension is https://github.com/testing-library/jest-native and is conspicuously missing the toHaveFocus
matcher).