---
title: Cypress Component Testing vs End-to-End Testing | TestingBot
description: 'Everything so far has been end-to-end testing: visit a URL, drive the
  whole application. Cypress has a second mode, component testing, that mounts a single…'
source_url:
  html: https://testingbot.com/resources/courses/cypress/component-testing
  md: https://testingbot.com/resources/courses/cypress/component-testing.md
---

Course

[Cypress Tutorial: First Spec to CI](https://testingbot.com/resources/courses/cypress)

Chapter 8 of 11

1. [1 Cypress Tutorial for Beginners](https://testingbot.com/resources/courses/cypress)
2. [2 Install Cypress and Run a First Spec](https://testingbot.com/resources/courses/cypress/install-and-first-spec)
3. [3 Selectors and the Cypress Command Queue](https://testingbot.com/resources/courses/cypress/selectors-and-the-command-queue)
4. [4 Cypress Assertions and Waiting Without Sleeps](https://testingbot.com/resources/courses/cypress/assertions-and-waiting)
5. [5 Fixtures and Network Stubbing with cy.intercept](https://testingbot.com/resources/courses/cypress/fixtures-and-network-stubbing)
6. [6 Custom Commands and Logging In Once with cy.session](https://testingbot.com/resources/courses/cypress/custom-commands-and-sessions)
7. [7 Cypress Configuration, Environment Variables and Retries](https://testingbot.com/resources/courses/cypress/config-and-environment-variables)
8. [8 Cypress Component Testing vs End-to-End Testing](https://testingbot.com/resources/courses/cypress/component-testing)
9. [9 Run Cypress on TestingBot and in CI](https://testingbot.com/resources/courses/cypress/run-cypress-on-testingbot)
10. [10 Debugging Cypress Tests](https://testingbot.com/resources/courses/cypress/debugging-cypress-tests)
11. [11 Knowledge check](https://testingbot.com/resources/courses/cypress/knowledge-check)

[Exit course](https://testingbot.com/resources/courses)

 Chapter 8 of 11 Beginner 5 min read 2 quick checks Updated Nov 2026 

# Cypress Component Testing vs End-to-End Testing
[Watch this chapter Starts at 4:50 in the 9:03 course video.](https://www.youtube.com/watch?v=Ty406iWkgN4&t=290s)On this page
1. [What changes](https://testingbot.com#what-changes)
2. [A React example](https://testingbot.com#a-react-example)
3. [Which one to write](https://testingbot.com#which-one-to-write)
4. [The limitation that matters here](https://testingbot.com#the-limitation-that-matters-here)

Everything so far has been end-to-end testing: visit a URL, drive the whole application. Cypress has a second mode, component testing, that mounts a single UI component in the browser without the rest of the app. This chapter is deliberately short. It shows what component tests look like, when they are the better choice, and the one limitation that matters for the rest of the course.

## What changes[#](https://testingbot.com#what-changes)

| | End-to-end | Component |
| --- | --- | --- |
| Starts with | `cy.visit(url)` | `cy.mount(<Component />)` |
| Needs | a running app (local or deployed) | your framework's dev server, which Cypress starts |
| Tests | user flows across pages, real backend | one component's behaviour, props and events |
| Speed | seconds per test | milliseconds per test |
| Spec location (default) | `cypress/e2e/` | next to the component, `*.cy.jsx` |

The commands, assertions, `cy.intercept` and the command log are the same in both modes, so everything from chapters 2 to 5 carries over.

## A React example[#](https://testingbot.com#a-react-example)

This example runs in its own small project, because component testing needs a framework and a bundler. It uses React 18 with Vite 6:

```bash
npm install --save-dev cypress@14.2.0 react@18 react-dom@18 vite@6 @vitejs/plugin-react@4
```

with a minimal `vite.config.js`:

```javascript
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

export default defineConfig({ plugins: [react()] })
```

When you run `npx cypress open` and choose **Component Testing** , Cypress detects the framework and bundler and writes the configuration for you. It comes down to this `cypress.config.js` (the scaffolded file may differ in quoting and comments):

```javascript
const { defineConfig } = require('cypress')

module.exports = defineConfig({
  component: {
    devServer: {
      framework: 'react',
      bundler: 'vite',
    },
  },
})
```

plus a `cypress/support/component.js` that registers `cy.mount`:

```javascript
import { mount } from 'cypress/react'

Cypress.Commands.add('mount', mount)
```

and a `cypress/support/component-index.html` with the element components are mounted into.

The component under test, `src/Counter.jsx`:

```javascript
import { useState } from 'react'

export default function Counter({ start = 0, onChange = () => {} }) {
  const [count, setCount] = useState(start)
  const increment = () => {
    setCount(count + 1)
    onChange(count + 1)
  }
  return (
    <div>
      <span data-cy="count">{count}</span>
      <button data-cy="increment" onClick={increment}>+1</button>
    </div>
  )
}
```

and its test, `src/Counter.cy.jsx`:

```javascript
import Counter from './Counter'

describe('<Counter />', () => {
  it('starts at the value it is given', () => {
    cy.mount(<Counter start={5} />)
    cy.get('[data-cy=count]').should('have.text', '5')
  })

  it('calls onChange with the new value', () => {
    const onChange = cy.stub().as('onChange')
    cy.mount(<Counter onChange={onChange} />)

    cy.get('[data-cy=increment]').click()

    cy.get('[data-cy=count]').should('have.text', '1')
    cy.get('@onChange').should('have.been.calledOnceWith', 1)
  })
})
```

Run it headlessly with:

```bash
npx cypress run --component
```

Both tests pass in a fraction of a second each. The second one shows what component tests are especially good at: `cy.stub()` replaces a callback prop, and the alias lets you assert how the component called it, something an end-to-end test can only observe indirectly.

A date picker has 14 edge cases (leap years, month boundaries, disabled dates). Where do they belong?

 In 14 end-to-end tests that each log in and open the booking page Nowhere; edge cases are for unit tests of the date library only In component tests that mount the date picker with different props, plus one end-to-end test of the booking flow

Component tests exercise the widget's own behaviour quickly and in isolation. One end-to-end test then proves the widget is wired into the real page and backend. Fourteen full flows would be slow and would fail for reasons unrelated to the date picker.

## Which one to write[#](https://testingbot.com#which-one-to-write)

A practical split many teams use:

- **Component tests** for anything whose behaviour depends mostly on props and user input: form widgets, tables with sorting, conditional rendering, error states.
- **End-to-end tests** for the flows that make money or lose it: sign-up, login, checkout, the main path through the product. Fewer of them, each covering more.

## The limitation that matters here[#](https://testingbot.com#the-limitation-that-matters-here)

Component tests run against a dev server on your machine. The [TestingBot Cypress documentation](https://testingbot.com/support/web-automate/cypress) lists Cypress Component Testing as not supported on the grid, so in chapter 8 only the end-to-end specs go to TestingBot. Run component tests locally or in your CI job with `cypress run --component`, where a Linux runner's Chrome or Electron is a good fit for them anyway: component behaviour rarely differs between operating systems the way full pages do.

Where does `cy.mount` come from in a component test?

 It is a custom command registered in `cypress/support/component.js` from the framework adapter, such as `cypress/react` It is a built-in command available in every Cypress spec It is provided by Vite

Cypress ships a mount function per framework, and the scaffolded support file registers it as `cy.mount`. That is why the same pattern works for React, Vue, Angular and Svelte, each with its own import.

[Previous · Chapter 7 Cypress Configuration, Environment Variables and Retries](https://testingbot.com/resources/courses/cypress/config-and-environment-variables) [Next · Chapter 9 Run Cypress on TestingBot and in CI](https://testingbot.com/resources/courses/cypress/run-cypress-on-testingbot)

On this page

1. [What changes](https://testingbot.com#what-changes)
2. [A React example](https://testingbot.com#a-react-example)
3. [Which one to write](https://testingbot.com#which-one-to-write)
4. [The limitation that matters here](https://testingbot.com#the-limitation-that-matters-here)

Certification

Earn the free, resume-worthy TestingBot Cypress Certification for this course.

[How it works](https://testingbot.com/resources/courses/cypress/certification)
