How to Run Cypress Tests for your Create-React-App Application

On This Page Why use Create-React-App to build your coveringJanuary 09, 2026 · 8 min read · Tool Comparison

How to Run Cypress Tests for your Create-React-App Application

When edifice coating with Create-React-App, insure your UI behaves as expected is key to delivering a smooth user experience. Cypress offers a straightforward and reliable way to automate testing immediately in the browser, making it easier to catch number before they hit production.

Overview

Create-React-App is a popular tool that simplifies setting up React applications with a ready-to-use development surround.

Running Cypress tests on a Create-React-App project helps automate end-to-end examination, ensuring your app works smoothly while speeding up bug detection and improving codification reliability.

Benefits of Running Cypress Tests for Create-React-App

  • Fast and easy setup cut for React projects
  • Real-time test execution with automatic reloads
  • Clear, detailed erroneousness messages and debugging tools
  • Reliable end-to-end testing in a real browser surroundings
  • Improves app stability by catching UI bug early
  • Integrates seamlessly with existing React workflows
  • Speeds up development with automated regression checks

This clause research the procedure of running Cypress tests on your Create-React-App project, assist you progress more robust and maintainable React applications with self-assurance.

Why use Create-React-App to construct your application

There are several reasons why you might choose to use Create React App over early choice for building your covering:

  • Simplicity:Create React App provides a simple and straightforward way to set up a development environment for building React coating. It include all the necessary tools and configurations out-of-the-box, which can save you time and effort.
  • Community Support:Create React App has a large and active community of developers who contribute to its growth, provide support, and create plugins and extensions that can be utilize with the tool. This can make it easier to chance help and resources when you ask them.
  • Opinionated Setup:Create React App provides a pre-configured and opinionated setup for progress React applications. This can help you avoid common mistakes and ensure that your coating follows best practices.
  • Familiarity:Create React App is wide used and has become a standard tool for building React applications. If you & # 8217; re already conversant with the puppet, it may be more efficient for you to use the Create React App than to memorise a new instrument.

Read More:

Why use Cypress for Testing Create-React-App Applications?

Running Cypress test on a Create-React-App provides various key benefits that improve both the development workflow and the overall quality of the application:

  • End-to-End Testing Made Simple:Cypress offers an intuitive interface to make and execute that mimic real user interaction, ensuring the app functions correctly from start to cease.
  • Fast Feedback Loop:With automatic reloads and real-time test execution, developers get immediate tryout consequence, accelerating debugging and shortening ontogeny cycles.
  • Reliable and Stable Tests:Running directly inside the browser, Cypress cater more consistent and dependable test results liken to tools relying on external browser mechanization.
  • Comprehensive Debugging Tools:Detailed error substance, screenshots, and video recordings during test runs make diagnosis and mend issues faster and easier.
  • Improves Code Quality:Machine-driven tests detect regressions and UI bugs early, helping teams deliver more stable and honest React applications with self-confidence.

To further enhance testing efficiency, offers a robust cloud-based platform that enable running Cypress tryout across a wide range of existent browser and devices. This ensures comprehensive test coverage and faster delivery cycles by validating app behavior in environments that closely match.

Set up the Create React App

To explore component try with Create React App, start by creating an application that includes a component examination. The sample app allow searching through a list of pre-populated name

Understand the App

Before installation and using Cypress for constituent testing, ensure all necessary dependencies are download and installed to run the application successfully.

1. Download the Github repositorywith the application.

2. Open the downloaded depository in VScode.

3. Click Terminal & gt; New Terminal.

4. Install the required dependencies:

npm install

5. Start the ontogeny server:

npm run dev

6. Verify the waiter is up and scat atlocalhost:5173.

Understand the Component

The following ikon shows the folder structure of the app:

The autocomplete.jsxfile include the state variables declaration:

  • hint– array of suggestions used to populate the autocomplete card.
  • suggestionIndex– index of the fighting suggestion used for keyboard navigation.
  • suggestionsActive– used to toggle the visibility of the autocomplete suggestions.
  • value– autocomplete suggestion that the user has selected.

It include theonChangeevent that will be triggered when a user starts typing and searching for a name. It likewise include theonClickevent that will be triggered when a exploiter clicks a name from the list that populates. ThekeyDowncase listens for keyboard navigation that a user performs. The Suggestions component holds the logic to return suggestions based on the user debut.

Read More:

Install Cypress in the App

To pen a component test for the component describe earlier, we need to establish Cypress.

1. Open the downloaded repository in VScode.

2. Click Terminal & gt; New Terminal.

3. Run the following command to instal Cypress:

SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.

npm install cypress -- save-dev

4. Run the following command to open Cypress splashboard:

npx cypress unfastened

Also Read:

Write the component test for Create-React-App expend Cypress

The component test to be written for the app will cover the next:

  • Verifies that the UI is up and scat.
  • Verifies that the filtering drop-down is functional.
  • Verifies that scrolling through to a name act right.

Read More:

To add the test to the app:

  1. In VSCode, open thesrc/componentdirectory.
  2. Create a new file,autocomplete.cy.jsx.
  3. Copy the undermentioned codification in the file. In theautocomplete.cy.jsxfile, the component is mounted using thecy.mountcommand and Save the file.
import Autocomplete from './autocomplete '; meaning countries from ' .. /data/countries '; describe ('Test the autocomplete functionality ', () = & gt; {beforeEach (() = & gt; {cy.mount (& lt; Autocomplete countries= {countries} / & gt;);}) it ('check everything is working in ui ', () = & gt; {cy.get (' [data-cy= '' head ''] ') .contains ('Search your land: '); cy.get ('input [type= '' text ''] ') .should ('have.value ', ``); cy.get (' [data-cy= '' suggestion-list ''] ') .should ('not.exist ');}) it ('check filter is act ', () = & gt; {cy.get ('input [type= '' text ''] ') .type ('no '); cy.get (' [data-cy= '' suggestion-list ''] ') .should ('be.visible ') .as ('suggestList '); cy.get (' @ suggestList ') .should ('have.length ', 1);}) it ('check selections are working ', () = & gt; {cy.get ('input [type= '' text ''] ') .as ('inputText '); cy.get (' @ inputText ') .type ('no ') .type (Cypress._.repeat (' {downArrow} {downArrow} ', 1)); cy.get (' [data-cy= '' suggestion-list ''] li: nth-child (3) ') .should ('have.class ', 'active '); cy.get (' @ inputText ') .type (Cypress._.repeat (' {upArrow} ', 1)); cy.get (' [data-cy= '' suggestion-list ''] li: nth-child (2) ') .should ('have.class ', 'active '); cy.get (' [data-cy= '' suggestion-list ''] li: nth-child (2) ') .click (); cy.get ('input [type= '' text ''] ') .should ('have.length ', 1); cy.get (' [data-cy= '' suggestion-list ''] ') .should ('not.exist ');})})

Run Component trial for Create-React-App using Cypress

After you have added the component test to your component, you can run the test using the Cypress dashboard.

1. In VSCode, clickTerminal & gt; New Terminal.

2. Run the next code:

npx cypress open

3. Click Component Testing & gt; Chrome, and so clickStart Component Testing in Chrome.

4. In the Cypressfascia, dogSpecsand double-click theautocomplete.cy.jsx file.

The test is consummate and the effect appears as follow:

Read More:

E2E test for Create-React-App employ Cypress

For running the Cypress E2E examination, using thebstackdemoweb app. The test will sign in using an account, log out the current exploiter, and then verify to be on the Sign in page.

Prerequisite

Before you can create the E2E specification for testing, you must install the cypress-xpath addiction.

  1. In VSCode, clickTerminal & gt; New Terminal.
  2. Open the root project directory.
  3. Run the following command to open Cypress:
npm install cypress-xpath

Write the E2E tryout for Create-React-App using Cypress

Create an empty spec using the E2E testing selection that Cypress provides.

1. In VSCode, clickTerminal & gt; New Terminal.

2. Run the following command to open Cypress:

npm cypress open

3. Click E2E Testing & gt; Chrome, and then clickStart E2E Testing in Chrome.

4. Click Continueto create an empty specification.

5. Set the name of the test ase2e.cy.jsand click Create spec.

6. In VSCode, open thecypress/e2e folder.

7. Open thee2e.cy.js file.

8. Copy the next code:

require ('cypress-xpath '), describe ('empty specification ', () = & gt; {it ('Bstack demo signin ', () = & gt; {cy.visit ('https: //bstackdemo.com/signin ') cy.get (`` # username '') .click (); cy.xpath (`` //div [schoolbook () ='demouser '] '') .click (); cy.get (`` # parole '') .click (); cy.xpath (`` //div [schoolbook () ='testingisfun99 '] '') .click (); cy.get (`` # login-btn '') .click (); cy.get (`` # logout '') .should ('have.text ', 'Logout ') cy.get (`` # logout '') .click (); cy.get (`` # signin '') .should ('have.text ', 'Sign In ')})})

Run your Cypress E2E examination for Create-React App

1. In VSCode, open the directory,bstackdemo-e2e.

2. Click Terminal & gt; New Terminal.

3. Run the next command to open Cypress:

npm cypress open

4. Click E2E Testing & gt; Chrome, and then clickStart E2E Testing in Chrome.

5. In the Cypressfascia, clickSpecsand double-click thee2e.cy.js file.

Read More:

The test is complete and establish the result as follows:

Read More:

Best Practices for scarper Cypress Tests on Create-React-App

Some of the good recitation that you can note before creating Cypress test cases are:

  • Aim to hold each spec file autonomous of each other. Reduce interdependencies.
  • Use assertions correctly such that Cypress commands progress only when denotative conditions are met.
  • Consider each scenario as an independent test case in isolation, sign into covering using programs, and deal your application & # 8217; s state.
  • Use the configuration file (*.cy.js) to set yourbaseURL.

For enhanced testing efficiency, supply seamless integration with Cypress, enabling tests to run across 3500+ real browser and devices in the cloud. With and local examination capabilities, BrowserStack helps speed up examination runs and securely test applications hosted behind firewalls.

Talk to an Expert

Conclusion

Efficacious testing is crucial to building dependable application, and Cypress offers a powerful solution tailored for Create-React-App projects.

By setting up and run both component and end-to-end examination with Cypress, developers can catch topic early, check smooth user experiences, and accelerate development round.

Adhering to outdo practices farther enhances test stability and maintainability, making Cypress an essential tool for modern React development.

Tags
64,000+ Views

# Ask-and-Contributeabout this topic with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free