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
3
votes
0 answers

How to mock react-navigation properly with jest?

I get the following during npm test: console.warn node_modules/react-navigation/src/react-navigation.js:23 `createNavigationContainer()` has been deprecated, please use `createAppContainer()` instead. You can also import createAppContainer…
2
votes
1 answer

Testing with jest and React Native Testing Library

I’m a newbie with testing I’m trying to get a grip on testing React Native with Expo, Jest and React Native Testing Library I wrote a simple screen that takes data from an API and writes the first element in the screen with a < Text > import {…
Rafael
  • 2,413
  • 4
  • 32
  • 54
2
votes
1 answer

How do I unit test a filter function in React Native?

I'm building a live music gig listing app in React Native with expo. An array of gig objects is fetched from firebase, with the following shape: gigs: [ { dateAndTime:{seconds:2345234748}, gigName: 'gigAtVenue', ... }, {...} ] In…
2
votes
1 answer

React native elements with jest not working

I'm using @testing-library/react-native but when I try to test a component that has any rneui: 4.0.0-rc-6 components I get several errors: The first now was Details: /Users/ep/myProject/node_modules/@rneui/themed/dist/index.js:1 …
2
votes
0 answers

Typescript error with tRPC useQuery argument types in Jest test

I have a monorepo which contains a React Native app. Within one of the components I have the following code: const { data: user, refetch } = trpc.useQuery([ "user.get", { id: state.user!.id }, ]) // Later I use the user I receive from this…
2
votes
0 answers

Web & mobile cross platform tests by merging react-testing-library with react-native-testing-library

I tried to merge both libraries for cross platform tests when using react-native-web, by resolving file extensions by platform so I can write 1 test for both web and mobile. It works for the most part, but as my app grew some tests became flaky. …
2
votes
1 answer

React Native Jest doesnt exit, and show the actual library as the cause of the problem

Im implementing tests framework (jest) in react native with testing-library/react-native, on an existing project. When I run their example (intro) the app give the infamous error: Jest did not exit one second after the test run has completed. when…
2
votes
2 answers

How to query a button with specific text with react native testing library

I am trying to query a button with a specific text in react native (yes there is another similar question but it didn't work for me). I want to getByRole the 'Login' Button of my screen but it gets my 'Register' Button as well. it('renders…
2
votes
0 answers

Jest doesnt recognize imported Styled Component from another library

React Native UI Library: Written in TypeScript and Styled Components. Written tests for the library using testing-library and jest. All the tests pass. React Native App: Written in TypeScript and Styled Components. This app imports the above UI…
2
votes
1 answer

How can I mock react-native-webview reload function?

I'm trying to create a unit test for a component in which I have a WebView. The problem is that inside this component I call the reload() function of the WebView. And when I run the test I get this error: Invariant Violation: nodeHandle expected to…
iVela
  • 1,160
  • 1
  • 19
  • 40
2
votes
3 answers

Why can't I install the React Native Testing library?

I'm new to app testing and have started delving into this topic since yesterday. I wanted to write tests for my React Native app and tried to install React Native Testing Library with this command: npm install --save-dev…
2
votes
1 answer

react-native-reanimated useSharedValue does not update in jest tests

I'm currently trying to figure out how to test reanimated 2 animations using useSharedValue. What makes 0 sense to me is the example given from…
2
votes
1 answer

No handler function found for event: "changeText"

I am trying out the React Native Testing Library with Expo / Jest for the first time. Following the tutorials, I can get a simple button to work test("Simple Button", () => { const mockFn = jest.fn(); const component = render(
2
votes
1 answer

Type Safety for Testing React Navigation with React Native

NAVIGATOR export type RootStackNavigator = { Welcome: undefined List: undefined } const Stack = createStackNavigator() const { Navigator, Screen } = Stack const Navigation = () => { return ( …
2
votes
1 answer

react-query how to call mutate from custom useMutation hook in Jest test

I'm running a React Native project where I'm testing custom hooks written with react-query. I'm using Jest, @testing-library/react-hooks and @testing-library/react-native. In my testing I can't seem to find a way to call the mutate function returned…