Questions tagged [react-native-testing-library]

The react-native-testing-library is a lightweight solution for testing your React Native components. It provides light utility functions on top of react-test-renderer letting you always be up to date with latest React features and write any component tests you like.

The react-native-testing-library is a lightweight solution for testing your React Native components. It provides light utility functions on top of react-test-renderer letting you always be up to date with latest React features and write any component tests you like.

This library is a replacement for Enzyme. It is tested to work with Jest, but it should work with other test runners as well.

https://github.com/callstack/react-native-testing-library

177 questions
0
votes
2 answers

Finding the buttons on the screen that have no text for the test

I am trying to write the tests for the NavBar component (using react-native-testing-library) that has several buttons that are basically just icons (using ui-kitten for react native). So I can't get these buttons by text (as there is none) but other…
0
votes
0 answers

How to mock useRef value change after click event in react native with jest and react native testing library

I have a component named MyComponent and it calls 2 APIs when it mounts. 1st API shows the initial data and when I click a particular button, it shows data from 2nd API. I have used useRef to decide which data to show. const MyComponent = () => { …
0
votes
1 answer

getByText doesn't find element with the text

I am starting using jest to test simple component SysError.js in my React Native 0.68 app. SysError displays some message on screen when it is called (routed by react-navigation 6.x) and the jest test is to check if the page view does contain the…
0
votes
1 answer

Why doesn't ref.current.focus() work when running tests via the @testing-library/react-native libary?

I'm attempting to write some tests for my react native app. A component in my app focuses a TextInput after a parent Pressable receives a press. I'm using a ref to identify and focus the TextInput element. My desired functionality works just fine…
Daniel Long
  • 1,162
  • 14
  • 30
0
votes
0 answers

expo-secure-store’s SecureStore.setItemAsync and getItemAsync not working with JEST

This question is specifically about expo-secure-store and jest. I am using expo-secure-store to store user's access_token when logging in. It works fine when running on device / simulator. But doesn't work at all in Jest tests; token comes back as…
0
votes
1 answer

How to test bottom tab bar using react native test library

I am trying to do testing for my react bottom tab bar component while testing it I am getting below error. I followed all the solutions available in this Link no luck for me. https://github.com/react-navigation/react-navigation/issues/8669 …
0
votes
1 answer

How to test arguments of custom hooks with jest

I have react-native screen component that i want to test using jest and @testing-library/react-native It looks something like this export const SelectPaymentIdScreen = () => { const { navigateToScreen } = useFlowNavigation(); const [orderId,…
MHB2011
  • 453
  • 1
  • 7
  • 22
0
votes
1 answer

How to test React Native Slider

I have worked on a Slider component using React Native Slider. And now I want to test it by simulating the sliding gesture. But according to React Native Testing Library documentation, there are only three gestures which…
0
votes
1 answer

How to test setState inside Firebase Auth onAuthStateChanged

I have already mocked Firebase onAuthStateChanged, so tests work flawlessly but I have this use case, in which it set's the user inside: const [isSignedIn, setIsSignedIn] = useState(false); const [displayName, setDisplayName] =…
0
votes
1 answer

react native testing library getByText in nested component

I have a component with the following structure {" "} Hi how are you ? when I do getByText("how are you ?") it doesn't find anything and I couldn't use custom matcher Any suggestion ?
0
votes
1 answer

How to get the whole components tree in jest and testing-library/react-native?

I have a component that I am testing using jest and react native testing library that looks something like this :
0
votes
1 answer

Error message from React native testing library: "Warning: You called act(async () => ...) without await." but i didn't

PASS app/components/lists/VideoCardList.test.tsx ● Console console.error Warning: You called act(async () => ...) without await. This could lead to unexpected testing behaviour, interleaving multiple act calls and mixing their scopes.…
0
votes
1 answer

SyntaxError: Unexpected token ',' --- error-guard.js

jest config is package json "jest": { "preset": "react-native", "setupFiles": [ "/jestSetup.js" ], "collectCoverage": true, "transform": { "^.+\\.(ts|tsx|js|jsx)$": "ts-jest" }, …
0
votes
1 answer

React native testing show component when logged

i am learning jest and react-native-testing. I have a profile file like this: ... const Profile = () => { const userInfo = useSelector(state => state.user); if(userInfo.isLogged) { return ( ) } else { return…
universe11
  • 703
  • 1
  • 11
  • 35
0
votes
1 answer

React native jest: While resolving: image-jest@1.0.0 npm ERR! Found: react@17.0.1

I am trying to install @testing-library/react-native to a freshly created expo-based react native application. For adding test cases, I followed the steps mentioned in https://docs.expo.dev/guides/testing-with-jest/ and installed jest and…
Sumit Surana
  • 1,554
  • 2
  • 14
  • 28