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.
- the refs all get mocked out in jest (i don't know enough about jest to know why).
- 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!
Source: stackoverflow.com
Related Query
- How to test React Native Module?
- In React Native how can I test my components with Shallow Rendering?
- How to test a TextField Material-UI element with React Jest?
- Jest and React Testing Library, how to test if an element is hidden?
- React Native: How to test if element is focused?
- How to properly test React Native Modals using Jest and Native Testing Library
- how to test a react hook that can have a ref of an html element passed to it
- Find Focused Element in React Test
- How can I get focused element and change state in React component?
- How to test button that on click renders html element within the same component in React testing library, Jest?
- How to locate react CreatableSelect element using python selenium test
- How to access a DOM element in React? What is the equilvalent of document.getElementById() in React
- How do you test for the non-existence of an element using jest and react-testing-library?
- How to get the width of a react element
- How to test a className with the Jest and React testing library
- How to test a react component that is dependent on useContext hook?
- How to unit test a method of react component?
- How to detect when a React Native app is closed (not suspended)?
- How to test style for a React component attribute with Enzyme
- How do I exit/shut down a React Native app?
- How do you make the ListHeaderComponent of a React Native FlatList sticky?
- How to get "key" prop from React element (on change)?
- How to get "key" prop from React element (on change)?
- React Native error: Element type is invalid: expected a string or a class/function but got: object
- How to concatenate JSX components in React Native
- How to test a prop update on React component
- Figuring out how to mock the window size changing for a react component test
- How to add sourcemap in React Native for Production?
- How to solve Warning: React does not recognize the X prop on a DOM element
- How do you center a div element in react w/out external css file
More Query from same tag
- Nodemon is not working : [nodemon] restarting due to changes
- nth-of-type, first-child does not work properly
- Refresh data of react app from backend every 2 seconds
- React: Close a modal clicking outside
- Nextjs + expressjs + Azure Web App : two factor authentication with express ('fs' can't be used on client side)
- react useContext implementation with hook
- Looping through simple object properties in react JSX
- How to redirect to component on click in React
- css or react Keep border focus when clicking my eye button
- How to map over array of multiple types in TypeScript?
- remove placeholder when item is added to array React
- How to mock in JEST document html elements like webview or iframe?
- Uploading image with Uppy trough Shrine return 405 Method Not Allowed
- Callback in props of React component - correct way to fire
- How to make loading screen run until all image are loaded?
- Mapping a nested array from JSON in react with a dropdown list
- React Context outside a React Component or alternatives
- react Error: It looks like you are passing several store enhancers to createStore()
- How to set custom style to antd Select?
- How to add props in react for styles?
- this variable in elements
- React Component for editting data
- react startkit to firebase I really don't know why this things.. happen
- How to create one store per instance in Redux?
- React JS updating setState in a for loop
- Need help declaring TypeScript interface in React
- How to enable watch for webpack MERN?
- How to increment and decrement date by 1 day using next and previous button in react?
- How can I change form input value in React and Redux?
- trying to fetch data with fetch and promise, doesnt work (react)