Cypress · Browser testing end to end
How does Cypress component testing work?
Short answer
Component testing mounts a component directly in a real browser with the mount helper, without the full application. It gives browser-accurate rendering with faster, more focused tests.
Component tests sit between unit tests and end-to-end tests. Instead of visiting a route, you mount one component with its props and interact with it. Cypress runs the component in a real browser, so layout, focus and events behave as they do in the app without starting the whole application.
import { mount } from "cypress/react";
import { Counter } from "../../src/Counter";
describe("Counter", () => {
it("increments when clicked", () => {
mount(<Counter start={0} step={2} />);
cy.contains("button", "Add").click();
cy.contains("[data-cy=value]", "2").should("be.visible");
});
});What to cover
- Rendering of props and conditional branches
- User interactions such as typing, selecting and keyboard behaviour
- Validation and error presentation inside the component
- Integration with a small state or context provider
- Visual states that are hard to reach through the full app
Component tests need the same mocking discipline as unit tests. Stub network calls at the boundary, provide the required context, and avoid importing the entire app shell. If a test needs routing, authentication and a database, it is probably an end-to-end test in disguise.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1How is component testing different from end-to-end testing?
- 2What does the mount helper do?
- 3When should a test move from component to e2e?
- 4How do you provide context to a mounted component?
Say it in the interview
Component testing mounts one component in a real browser with the framework's mount helper. I pass explicit props and stub the boundaries the component needs, so the test focuses on rendering and interaction without the whole app. It is faster and more targeted than e2e, but when a test needs routing, auth and a database, I move it to end-to-end. Both modes use the same runner.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Cypress mock interview and get scored feedback on depth, clarity and confidence.