Next-Gen App & Browser Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Test your UI components in isolation with Cypress component testing. Debug faster, catch issues early, and ensure reliable, scalable front-end code.
Chosen Vincent
January 11, 2026
Cypress has become a popular choice for front-end developers, especially when it comes to building modern web applications. Cypress component testing provides a way to test individual modules of your user interface. This ensures that components behave as expected throughout development.
Cypress component testing involves testing individual UI components like buttons, forms, or widgets in isolation, directly in the browser. It helps verify how components behave under different states without needing to launch the entire application.
Importance of Cypress Component Testing
Best Practices for Cypress Component Testing
Component testing in Cypress is a technique to verify if an individual part of a user interface, like a button or form, works on its own. With Cypress, you can run these tests right in the browser to see exactly how your component behaves in different conditions without the need to start the whole web application.
The main difference between Cypress component testing and Cypress end-to-end testing is their scope. Component testing focuses mainly on a single UI element in isolation whereas E2E testing covers the entire application workflow.
Let’s dive into Cypress component testing using a real-world example. I cloned a section on the Write for Us page from the TestMu AI website with React and SASS.
You can either use this project to follow along, or you can use any existing React project. You’ll still get the same result. All you have to do is follow the steps accordingly.
If you want to use the project, clone this Cypress Component Testing GitHub repository.
To follow along with this Cypress component testing tutorial, make sure to:
Note: Run Cypress component tests across 50+ browser versions. Try TestMu AI Today!
Before configuring Cypress for component testing, you need a project to work with.
Note: If you already have a React project, you can skip to the next section.
1. Create a React App
Use Vite for a rapid, modern development experience. Open your terminal and run:
npm create vite@latest <project-directory-name>This command will launch an interactive setup where you:
2. Move Into Your Work Directory and Install Dependencies
Run the below command to move into your work directory and install the dependencies:
cd <project-directory-name>
npm install3. Add SASS for Styling (Optional)
Run the below command to install SASS:
npm install sass4. Folder structure
This is how a folder structure looks like:
cypress-component-testing/
├── node_modules/
├── public/
├── src/
│ ├── assets/
│ ├── components/
│ │ └── Form.jsx
│ │ └── Navbar.jsx
│ │ └── SubmitBlog.jsx
│ │ └── SubmitBlogContent.jsx
│ ├── App.jsx
│ ├── App.scss
│ └── main.jsx
├── package.json
├── vite.config.js
└── README.mdYours might look different, maybe due to folder name, file name, or how you created your app, but in the end, you’ll still achieve the same result if you follow up.
Our main focus in this Cypress tutorial will be on the <Form /> component. We’ll use Cypress to test the input fields, checking their placeholders and ensuring they accept user input.
5. Add your React component
Here’s what App.jsx file looks like:
import Navbar from './components/Navbar/Navbar';
import SubmitBlog from './components/SubmitBlog/SubmitBlog';
function App() {
return (
<>
<Navbar />
<SubmitBlog />
</>
)
}
export default AppThis is not our main focus, but it’s good that you see the code in each file down to the very one we’re testing, especially if you want to practice with this same code example.
In the App.tsx component, we have <Navbar /> and <SubmitBlog />. However, we’re more concerned with the <SubmitBlog /> component, which contains a form we’ll be working with.
import Navbar from './components/Navbar/Navbar';
import SubmitBlog from './components/SubmitBlog/SubmitBlog';
function App() {
return (
<>
<Navbar />
<SubmitBlog />
</>
)
}
export default AppThe SubmitBlog component contains SubmitBlogContent and Form. The SubmitBlogContent component is an image and title for the section. Finally, here’s the Form.jsx code we want to test:
export default function Form() {
return (
<form className={styles.submitBlogForm} onSubmit={(e) => {e.preventDefault();}}>
<div className={styles.nameFields}>
<input type="text" placeholder="First Name*" required />
<input type="text" placeholder="Last Name*" required />
</div>
<input type="email" placeholder="Email*" required />
<input type="text" placeholder="Designation*" required />
<div className={styles.contactFields}>
<select name="" id="" className={styles.countrySelect} required>
<option value="">Nigeria (+234)</option>
<option value="">USA (+1)</option>
<option value="">UK (+44)</option>
<option value="">Algeria (+213)</option>
</select>
<input type="number" placeholder="Phone Number*" required />
</div>
<input type="text" placeholder="Social Media Profile (LinkedIn/Twitter)*" required />
<textarea placeholder="Provide Work Samples"></textarea>
<button>Submit</button>
</form>
)
}
Here’s the styling:
.submitBlogForm {
display: flex;
flex-direction: column;
gap: 10px;
background-color: #fff;
border-radius: 8px;
padding: 20px;
input {
padding: 15px 10px;
font-size: 16px;
width: 100%;
border: none;
background-color: transparent;
border-bottom: 1px solid #ccc;
&:focus {
outline: none;
}
&::placeholder {
font-size: 14px;
}
}
textarea {
padding: 15px 10px;
font-size: 14px;
width: 100%;
height: 100px;
background-color: transparent;
border: 1px solid #ccc;
&:focus {
outline: none;
}
&::placeholder {
font-size: 14px;
}
}
.nameFields {
display: flex;
gap: 20px;
input {
flex: 1;
border-bottom: 1px solid #ccc;
}
}
.contactFields {
display: flex;
gap: 20px;
input {
flex: 1;
border-bottom: 1px solid #ccc;
}
.countrySelect {
width: 30%;
padding: 15px 10px;
font-size: 14px;
border: none;
background-color: transparent;
border-bottom: 1px solid #ccc;
&:focus {
outline: none;
}
}
}
button {
padding: 15px;
background-color: transparent;
border: 1px solid black;
border-radius: 5px;
cursor: pointer;
width: 150px;
color: #333;
margin: 0 auto;
margin-top: 20px;
}
}Now that we have a working React project, the next step is to set up Cypress for component testing. Cypress allows you to test individual components of your application, which makes it easier to identify UI bugs early in development.
1. Install Cypress
First, install Cypress as a development dependency:
npm install cypress --save-dev2. Open Cypress
Once installed, launch Cypress using:
npx cypress openThis command opens the Cypress App (Test Runner). You’ll be prompted to choose the type of testing:
For this tutorial, select Component Testing.

3. Configure Framework and Bundler
After selecting component testing, Cypress will ask you to configure your setup:
This ensures Vite is available as a dev dependency for Cypress to use internally.

4. Verify Vite Installation
Check your package.json file in the devDependencies section. If Vite is missing, install it:
npm install -D vite5. Finalize Setup in Cypress
Click “Continue” in the Cypress app.

Select your preferred browser (I am using Electron), and then click “Start Component Testing in Electron”.

We’ll write a Cypress component test to check:
First, add data-cy attributes to the form elements in the Form.jsx file:
<input type="text" placeholder="First Name*" required data-cy="first-name" />
<input type="text" placeholder="Last Name*" required data-cy="last-name" />1. Create the Test File
Inside the cypress folder:
cypress/
└── component/
└── Form.cy.jsx2. Write the test
import React from 'react';
import Form from '../../src/components/Form/Form';
import '../../src/components/Form/Form.module.scss';
describe('Form component', () => {
beforeEach(() => {
cy.mount(<Form />);
});
it('renders all required fields', () => {
cy.get('[data-cy="first-name"]').should('exist');
cy.get('[data-cy="last-name"]').should('exist');
cy.get('[data-cy="email"]').should('exist');
cy.get('[data-cy="designation"]').should('exist');
cy.get('[data-cy="country"]').should('exist');
cy.get('[data-cy="phone"]').should('exist');
cy.get('[data-cy="social"]').should('exist');
cy.get('[data-cy="samples"]').should('exist');
});
it('Fills and submit form', () => {
cy.get('[data-cy="first-name"]').type('Chosen');
cy.get('[data-cy="last-name"]').type('Vincent');
cy.get('[data-cy="email"]').type('[email protected]');
cy.get('[data-cy="designation"]').type('Software Engineer');
cy.get('[data-cy="country"]').select('nigeria');
cy.get('[data-cy="phone"]').type('1234567890');
cy.get('[data-cy="social"]').type('https://www.linkedin.com/in/chosenvincent1/');
cy.get('[data-cy="samples"]').type('https://www.lambdatest.com/blog/smooth-scroll-in-css/');
cy.get('[data-cy="submit"]').should('exist').click();
});
});Key Notes:
Start Cypress in component testing mode:
npx cypress open --componentOr use:
npx cypress openThen click the Form.cy.jsx file to run the test. Cypress will render the form and execute all assertions in real-time.

Running Cypress component tests locally works well, but for larger test suites, team collaboration, or CI integration, running tests on the cloud is better. We’ll use HyperExecute, an end-to-end test orchestration platform from TestMu AI.
We’ll use a simple React project from the Cypress GitHub Repository, specifically the “react-webpack5-js” example.
HyperExecute provides a pre-configured environment for faster testing. It supports Cypress, Selenium, Playwright, Appium, and multiple languages like Python, Java, C#, PHP, and Go.
1. Create a folder and YAML file
Create a folder in your project root, and inside it, create matrix.yml with the following configuration:
---
version: 0.1
runson: ${matrix.os}
cypress: true
cypressOps:
Build: "[Matrix] Cypress Component Testing"
Tags: ["HYP-Cypress", "macOS", "Matrix", "Accessibility"]
BuildTags: ["HYP-Cypress-v10"]
pre:
- npm install
- npm install cypress --save-dev
- npm i lambdatest-cypress-cli
matrix:
os: [linux]
browser: ["chrome"]
files: ["Welcome.cy.js", "LoginForm.cy.js", "InputField.cy.js", "Button.cy.js"]
parallelism: 5
testSuites:
- npx cypress run --component --spec ./src/components/$files --browser=$browser --headed --config video=true
jobLabel: [cypress-v10, mac, matrix]2. Download and Add HyperExecute CLI
Download the HyperExecute CLI for your OS and place it in your project root. It reads the YAML configuration and uses your TestMu AI credentials.
3. Upload and Run Your Tests
Run this command in your terminal to upload and run your tests on HyperExecute:
./hyperexecute --config yaml/matrix.yml --force-clean-artifacts --download-artifacts --user <user_name> --key <access_key>Replace <user_name> and <access_key> with your TestMu AI credentials.
4. View Your Tests on HyperExecute Dashboard
Navigate to HyperExecute, and click your test to view execution tasks and logs.

To effectively carry out component testing with Cypress, you need to follow some best practices. They will make your tests reliable, readable, and easy to maintain:
They are too generic and are more likely to change during code refactoring. Instead, use custom attributes like data-cy or data-testid. They are more stable and specifically meant for testing.
Avoid testing too many things in a single test block. Isolating your test makes it easier to identify where something is going wrong.
// Good
it('shows validation error for empty email', () => { ... });
// Bad
it('renders, fills form, validates fields, submits, and checks success message', () => { ... });
beforeEach(() => {
cy.mount(<Form />);
});
// Good
it('displays an error when email is empty');
// Bad
it('checks if email input works');
One way or the other, issues will come up when writing or running Cypress component tests. Here are some common issues and how to troubleshoot them.
Possible causes include:
Make sure the component is mounted correctly, and if it requires props, pass them.
cy.mount(<UserCard user={prop} />);
Also, check the browser console in the Cypress Test Runner for any React errors.
Always import styles manually in your test file.
import '../../src/components/Form/Form.module.scss';
If you’re using CSS modules or SCSS, make sure your build tool (like Vite or Webpack) is configured to handle them in Cypress.
beforeEach(() => {
cy.mount(<Form />);
});
Also, avoid using .only and .skip except when you’re debugging.
Make sure you’re passing all required props in cy.mount().
To fix this, use the .cy.jsx extension.
Form.cy.jsx
And import React in your test file:
import React from 'react';
Cypress component testing bridges the gap between isolated unit tests and full end-to-end scenarios, giving developers confidence that their UI behaves as expected. By setting up the environment properly, following best practices, and organizing tests effectively, you ensure faster feedback and fewer regressions. Leveraging cloud platforms further enhances Cypress testing with scalability, and parallel execution, making the workflow efficient for modern teams.
Did you find this page helpful?
More Related Hubs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance