Skip to content
tezvyn:

Cypress Component Testing: Test in a Real Browser

Source: docs.cypress.ioEasyHow cards are made

Cypress Component Testing: Test in a Real Browser

Cypress component testing mounts your UI components in a real browser, not a simulated DOM, so you test them exactly as users see them. Use it for faster feedback on individual React, Vue, or Angular components.

Why it exists

Teams need faster feedback on their UI components. Catching a component bug in isolation is far cheaper and quicker than finding the same bug in a full end-to-end test or, worse, in production. Cypress component testing aims to close that feedback loop earlier, reducing the cost of fixing defects.

The mental model

Think of it as putting a single Lego piece under a microscope instead of looking at the entire assembled castle. Cypress component testing mounts your component directly in a real browser, not a simulated environment, so you test it exactly as it will behave for your users. You see it render visually and can interact with it using your browser's DevTools.

How it works

Cypress uses an official mounting library for your framework (like React, Vue, or Angular) to render just that component. It runs tests inside the Cypress App, which is a real browser. It features automatic waiting, so your assertions only run after the component has rendered, eliminating the need for manual waitFor or timeouts. You can also use built-in spies, stubs, and network interception to isolate dependencies and test edge cases without a running backend.

When to use it

Use it to verify the behavior and appearance of individual UI components in isolation. It's ideal for teams using React, Vue, Angular, or Svelte who want to write tests with less boilerplate and get fast, visual feedback. Component tests live in the same project as your end-to-end tests, providing a single, unified view of quality.

When not to use it

Do not use it to verify a complete user journey that spans multiple pages or components, like a full checkout process. For that, you need an end-to-end test. Component testing is for testing parts in isolation, not the integrated whole.

One canonical example

A developer wants to test a new 'Submit' button component. Using Cypress, they mount the button, then write a test to assert that clicking it triggers a specific event. They can use a Cypress spy to verify an event handler was called, all without needing the rest of the application to be running or having a live backend.

Interview question

What is the primary environment where Cypress Component Tests execute components?

  • a.A simulated browser environment that mimics user interaction.
  • b.A headless browser instance, optimized for speed without a UI.
  • c.A Node.js runtime, where UI components are rendered virtually.
  • d.A real browser, allowing direct visual inspection and interaction.Correct
Why?

Cypress component testing mounts components directly in a real browser, not a simulated environment, allowing visual interaction and testing exactly as users would experience it. Option A is incorrect because the card explicitly states it is 'not a simulated environment'.

Just read this? Test yourself on what you have been reading.

Read the original → docs.cypress.io

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles