How to Perform Cypress React Native App Testing

Alex Anie

Posted On: July 8, 2025

view count22525 Views

Read time9 Min Read

Cypress is primarily used for testing web applications. However, if you want to use Cypress for React Native apps, you can leverage tools like React Native Web or Expo’s Web-only mode. This enables you to test React Native apps with Cypress.

Overview

You can perform React Native app testing with Cypress using tools like React Native Web or Expo Web.

How to Run Cypress React Native App Tests

  • Set up your React Native project to run in a browser using tools like Expo or React Native Web.
  • Clone a sample GitHub repository or use your own React Native app configured for web rendering.
  • Install all required dependencies using the npm install command.
  • Start the development server using the npm start command. It will open your web application in the browser at a local address.
  • Install Cypress using the npm i -D cypress command as a development dependency in your project.
  • Launch the Cypress Test Runner using the npx cypress open command to access the testing interface.
  • Configure Cypress by setting the baseURL to point to your running web app.
  • Write a Cypress test to simulate user actions, such as visiting a page and checking if specific text or elements appear.
  • Open the Cypress Test Runner, select your test file, and run the test to see it interact with your web application.

Getting Started With Cypress React Native App Testing

Let’s explore how to run a Cypress React Native app test in a local development server.

Set up a Project

To get started with Cypress React Native app testing, you need to set up your development server to run the app.

Since Cypress requires a DOM environment, we will use Expo to render a React Native app in a browser.

  1. Clone this GitHub repository for Cypress React Native app testing.
  2. Install the required dependencies using the following command.
  3. Start the development server using the following command:

This will open the web application at http://localhost:8081. The npm start command internally runs expo start to launch the web application via Expo CLI.

Info Note

Run Cypress tests across 40+ browser versions on the cloud. Try LambdaTest Today!

Install Cypress

Before writing your Cypress React Native app tests, make sure your web application is running at http://localhost:8081/.

  1. Install Cypress as a dev dependency using the command below:
  2. Open the Cypress Test Runner using the command below:
  3. Set a global baseUrl in Cypress. This URL indicates where the web application runs.

Write the Tests

Once Cypress is set up correctly, you’ll find a sample test spec.cy.js file in the default cypress/e2e/ folder.

To organize your tests better, rename this file to hello.cy.js. Then, replace the contents with the test code below:

In the above test file, the cy.visit(‘/’) command navigates to the root file component in the React Native app.

And then, the cy.contains() method gets the DOM element that contains the text argument. The should() command is used to set an assertion for the element to be visible.

This test ensures that the main banner text “24/7 online shopping, delivered anywhere you are!” is rendered correctly in the browser.

Run the Tests

To launch the Cypress Test Runner, run the following in your terminal:

Then, select the hello.cy.js file from the test list in the Cypress Test Runner. Click to run the test, and you should see it pass.

Run the Tests

How to Test React Native Apps With Cypress on Cloud?

Testing React Native apps with Cypress using cloud-based testing platforms offers several key benefits that enhance both development efficiency and test reliability.

For cross-browser cloud execution, you can use platforms like LambdaTest. It is a GenAI-native test execution platform that allows you to run automated tests on its Cypress cloud. You can run tests across multiple browsers and operating systems without maintaining local infrastructure.

To get started, check out this documentation on Cypress testing with LambdaTest.

To run the Cypress React Native test on LambdaTest, make sure you have set up the LambdaTest Tunnel. You can check this documentation on setting up LambdaTest Tunnel.

Now, run the following command to execute the tests:

When you run the above command, it will create the he_conv.yaml file and other LambdaTest configuration files.

You can now check the test results from your LambdaTest Web Automation dashboard.

unnamed (11) (1)

Validating Dynamic Content in React Native Using Cypress

It is important to ensure React Native apps function as expected during tests, especially as UI behavior depends heavily on dynamic state changes.

The testID Props in React Native

In React Native, UI components don’t support traditional attributes like id or class. Instead, you use the testID prop to assign a unique identifier to a component for testing. This enables Cypress to target and interact with components during tests.

Example:

For Cypress, the test will look like:

Validate State in React Native

State management in React Native is commonly handled using the useState hook, which tracks and updates values dynamically based on user interactions.

Here’s an example of a Rate component that updates a counter each time a button is clicked. This test verifies that the button click correctly updates the state and UI.

Use Cases for React Native Testing With Cypress

Let’s look at some use cases for React Native app testing, like network responses, loading indicators, and stubbing network requests using Cypress.

Testing Network Response

When data is fetched using useState and useEffect in React Native, it’s often rendered in components like FlatList. You can use Cypress to validate if the data is fetched correctly using the cy.intercept() method.

Example of FlatList data fetching:

Here is the Cypress test to ensure data is fetched:

Testing Loader Component

To test if the ActivityIndicator (loading spinner) shows while data is loading:

Here is the Cypress test to ensure the loader is visible while fetching data:

Stubbing a Network Request

You can stub network requests in Cypress to test your app’s behavior with predefined data without hitting the actual API.

Example of stubbing an API request:

Stubbing Request Data With Fixtures

You can store static mock data in the cypress/fixtures folder and use it in tests.

Example of stubbing request data:

Here is the Cypress test to stub data request data with fixtures:

Conclusion

While Cypress is not for testing native mobile apps directly, it can still be useful in React Native projects, especially when the web application runs in a browser using tools like Expo Web or React Native Web.

In this blog, we explored how to set up a React Native project, install Cypress, write basic Cypress React Native app tests, and handle common scenarios like validating content, checking component states, and stubbing network responses.

Frequently Asked Questions (FAQs)

What is the best testing tool for React Native?

The best testing tool for React Native depends on your needs, but Detox is widely used for end-to-end testing. For unit and component testing, Jest and React Native Testing Library are popular choices.

What is Cypress in React?

Cypress is an end-to-end testing framework that can be used to test React applications in the browser. It allows you to simulate real user interactions and verify UI behavior.

What types of tests can Cypress handle in a React Native project?

Cypress can handle UI, navigation, and user flow tests, but only for the web-rendered version of the app, not the native mobile app.

Can I share the test logic between Cypress and native tests?

You can share partially. While test structure and business logic can be shared, the actual test implementation must match the platform (web vs. native).

What are the limitations of using Cypress with React Native?

Cypress doesn’t support native mobile environments (like Android or iOS), so it can’t interact with native APIs or components directly.

Citations

Author Profile Author Profile Author Profile

Author’s Profile

Alex Anie

A Front End Technical Writer. I write blogs on Front End Technologies, such as HTML, CSS, JavaScript. When I am not coding, I enjoy watching tutorials and listening to twitter spaces. I live in Lagos, Nigeria

Blogs: 18



linkedintwitter

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free