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

How to mock react-native-copilot?

Trying to mock with jest react-native-copilot This is the point in the screen where the module is imported. import { walkthroughable, CopilotStep } from 'react-native-copilot'; ... const CopilotText = walkthroughable(Text); ...
0
votes
1 answer

Jest - Could not locate module ./fonts/galio.ttf mapped as

I'm new to react native testing and recently I got this error. I'm still unable to find a correct solution to fix this. Could you please someone can help on this? Thanks in advance. Configuration error: Could not locate module ./fonts/galio.ttf…
TIJ
  • 2,771
  • 3
  • 19
  • 32
0
votes
1 answer

TouchableOpacity does not show disabled and activeOpacity props

I am trying to test this simple button: import React, { FC, ReactNode } from 'react'; import { TouchableOpacity, GestureResponderEvent, ViewStyle } from 'react-native'; type Props = { style: ViewStyle; onPress: (event: GestureResponderEvent) =>…
0
votes
1 answer

Can't find named elements with react-native-testing-library

I'm trying to get an element by its placeholder text but react-native-testing-library keeps throwing me the same errors: expect(received).toEqual(expected) // deep equality Expected: "Cirurgião" Received: {"_fiber": {"_debugHookTypes":…
0
votes
1 answer

jest error: const warnedKeys: {[string]: boolean} = {};

If I run yarn test, which runs jest, I get the following error: C:\react-native-project\node_modules\react-native\Libraries\Utilities\warnOnce.js:15 const warnedKeys: {[string]: boolean} = {}; But that only happens if I follow the directions…
haleonj
  • 1,438
  • 3
  • 16
  • 30
0
votes
1 answer

Having difficulty finding elements with native testing library

I'm fairly new to using the react-testing-library, specifically the native-testing-library. I seem to be running into trouble querying elements. In the example below I would expect the test to pass but it can't seem to find the element. I have a…
0
votes
1 answer

How to get props of rendered component

Imagine, I have a react native component: const HelloWorld = (props) => ( Hello World ) I want to run a test to refer to HelloWorld component itself and check for a prop. How do I access HelloWorld itself and retrieve its…
helloworld
  • 2,179
  • 3
  • 24
  • 39
0
votes
1 answer

react native testing snapshot with multiple state renders?

I have a component that sets state several times in its componentDidMount method. For example: componentDidMount = async () => { this.setState({ waiting: true }); try { const data = await this.fetchData(); this.setState({ data }) }…
devshorts
  • 8,572
  • 4
  • 50
  • 73
0
votes
1 answer

React Native : Update context api values in jest unit tests

I am writing unit tests for validations of a react native form with few text inputs and a custom dropdown field. I am using jest with react-native-testing-library. The form is validated on submit btn press. The form values are saved to, and accessed…
0
votes
1 answer

Test for alerts with react-native-testing-library

Can react-native-testing-library find an alert, created with Alert.alert()? My app creates the alert as expected but this test is failing: // test const Wrapper = props => (
Jonathan Tuzman
  • 11,568
  • 18
  • 69
  • 129
-1
votes
1 answer

jest multistep form testing - is it possible to split the test into multiple tests but with one render?

I have a multi-step Sign Up form in my React Native application and I'm testing it with jest and RNTL. It works fine, but I just don't like how it looks. Now it's just one big test function which renders the screen in the beginning and then goes…
-1
votes
1 answer

How to mock a state value in jest

A react native 0.70 component displays items in FlatList. The array items is a state and is assigned value in hook useEffect. I would like to jest (0.29) it to see if a item's name is shown up on screen so a mock of state items is needed. Here is…
1 2 3
11
12