DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk7 min

Test-Driven UI Development With Cypress Component Testing

Use Cypress Component Testing as a browser-based feedback loop for UI behavior: specify what users should see, mount the component, interact, assert, and iterate.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Cypress Component Testing can provide a fast feedback loop for UI work: write a test for a user-visible behavior, mount the component in a real browser, observe the failing expectation, implement the behavior, and rerun the spec. That red/green/refactor sequence is a development practice—not a workflow Cypress requires. Cypress supplies the browser mounting, interaction, and assertion tools; you choose the test-first approach.

What Cypress Component Testing covers

Cypress mounts an individual component in a real browser rather than a simulated DOM. A component spec can inspect the rendered UI, interact with controls, and assert visible output or callback behavior. See Cypress’s component-testing getting-started guide and cy.mount() API.

The boundary is important: component testing does not visit your deployed staging or production application. Cypress starts a development server, compiles component specs and support files, and serves those test resources. This makes the layer useful for isolated rendering and behavior; it does not cover the complete deployed journey, routing, or integrated services. Keep end-to-end tests for flows where those broader boundaries matter. See Cypress component testing configuration.

How do I set up Cypress Component Testing?

  1. Start Cypress Launchpad. Use its component-testing setup flow to detect the UI framework and bundler and scaffold the configuration. The exact install command depends on the project’s package manager and existing Cypress setup; follow the project-specific instructions in the getting-started guide.
  2. Confirm the component dev server configuration. Cypress recommends specifying the framework and bundler. For a React project using Vite, a CommonJS config can look like this:
    const { defineConfig } = require('cypress')
    
    module.exports = defineConfig({
      component: {
        devServer: {
          framework: 'react',
          bundler: 'vite',
        },
      },
    })

    Adapt the values to the application rather than copying this React/Vite example unchanged.

  3. Check project configuration visibility. Cypress may reuse a discoverable Vite or Webpack configuration. If aliases, plugins, or framework-generated settings are not visible to Cypress, configure the relevant viteConfig or webpackConfig explicitly. Nuxt is a notable case: Cypress does not execute nuxt.config, so aliases and auto-imports used by mounted components may need explicit treatment. See the configuration guide and Vue overview.
  4. Verify framework compatibility. The Cypress documentation current as of 2026-10-03 lists React 18–19 with Vite 8 or Webpack 5; Next.js 15–16 with React 18–19 and Webpack 5; Vue 3 with Vite 8 or Webpack 5; Angular 21–22 with Webpack 5; and Svelte 5 with Vite 8 or Webpack 5, labeled Alpha. These are version-specific compatibility listings, not a guarantee for every project configuration. Recheck the current support matrix before choosing a setup.

Framework-specific constraints matter. Cypress’s React overview describes React 18 and 19 support with Vite, Webpack, and Next.js. The Vue overview covers Vue 3 with Vite or Webpack and does not provide Nuxt with dedicated framework treatment. The Angular overview covers Angular 21 and 22; Angular dependencies, standalone components, and test setup can require framework-specific handling.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If Cypress does not officially support a framework, its custom framework mechanism is an extension route. Community integration through that route should not be treated as equivalent to Cypress’s first-party framework support.

How do I write my first component test?

Start with a single observable behavior. This React example tests that clicking an increment button changes the displayed count. The first version is deliberately a failing specification: the component renders zero but does not yet implement the click behavior.

1. Write the failing spec

import Counter from './Counter'

describe('<Counter />', () => {
  it('increments the displayed count when clicked', () => {
    cy.mount(<Counter initialCount={0} />)

    cy.get('[data-cy="count"]').should('have.text', '0')
    cy.get('[data-cy="increment"]').click()
    cy.get('[data-cy="count"]').should('have.text', '1')
  })
})

This assumes the project’s Cypress component setup supports JSX and has registered cy.mount(), as in Cypress’s React examples. The selector names are part of this example’s component contract; use selectors or accessible user-facing attributes that remain stable for your own UI.

2. Implement only what satisfies the expectation

export default function Counter({ initialCount = 0 }) {
  const [count, setCount] = React.useState(initialCount)

  return (
    <div>
      <output data-cy="count">{count}</output>
      <button
        data-cy="increment"
        onClick={() => setCount((current) => current + 1)}
      >
        Increment
      </button>
    </div>
  )
}

Import React or the state hook according to the project’s JSX transform and coding conventions. Run the spec again: the expected sequence is a failure before the implementation and a passing assertion afterward. Cypress demonstrates mounting, interactions, and assertions; this deliberate red-then-green sequence is a practical TDD method, not a Cypress-mandated process. See the React component-testing guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

3. Add a callback expectation when behavior is external

For a component whose responsibility is to notify its parent, pass a Cypress spy and assert the event rather than testing unrelated parent state:

it('reports the selected value', () => {
  const onChange = cy.spy().as('onChange')

  cy.mount(<Choice onChange={onChange} />)
  cy.get('[data-cy="choice-a"]').click()

  cy.get('@onChange').should('have.been.calledWith', 'a')
})

Use the actual callback prop and argument shape for the component. Cypress’s framework examples show spies used to verify event behavior; see the React guide and Vue examples.

Use the red/green/refactor loop deliberately

  1. Describe the user-visible result. Name the spec for the behavior, such as “increments the displayed count when clicked,” instead of describing an implementation detail.
  2. Mount meaningful initial inputs. Supply the props, state, or dependencies that put the component in the scenario being tested.
  3. Interact as a user would. Query an appropriate rendered control, click or type, and assert the resulting visible state or callback.
  4. Run the spec before changing the component. Confirm that the new expectation fails for the intended reason rather than because the test cannot mount.
  5. Make the smallest implementation change. Rerun the spec and verify the expectation passes.
  6. Refactor under the passing test. Add focused cases for meaningful alternate props, empty states, and boundaries where they affect user-visible behavior.

This sequence is an editorially recommended application of TDD. Cypress documentation supplies the component-testing primitives but does not prescribe this formal methodology.

Adapt the mount pattern to React, Vue, and Angular

React

React specs mount JSX with cy.mount(<Component ... />). Props belong directly on the component, and normal Cypress commands can interact with the rendered result. When many tests need the same providers or application context, define a reusable custom mount command that wraps the component; keep scenario-specific props explicit in each spec. See React component testing and the mount API.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Vue

Vue mounts a component definition and supplies props through an options object:

import MyButton from './MyButton.vue'

it('renders the supplied label', () => {
  cy.mount(MyButton, { props: { label: 'Save' } })
  cy.contains('button', 'Save').should('be.visible')
})

To test an emitted change, pass a Cypress spy through the relevant event prop and assert that it received the expected value. A reusable mount command can install shared Vue plugins. See Vue examples and the Vue overview.

Angular

Angular specs can set component properties in mount options and provide needed imports, declarations, or providers for the component’s dependencies. Standalone components have distinct setup considerations, so use the Angular-specific mounting recipe rather than assuming the React or Vue setup applies. See Angular examples and the Angular overview.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose the right test boundary

Test layer What runs Useful coverage What it does not establish
Cypress Component Testing An individual component mounted in Cypress’s browser testbed with a development server. Rendered UI, component interactions, props and callback behavior. That a deployed application’s complete route, service integration, or user journey works.
End-to-end testing A broader application flow in an application environment. Integrated journeys across routing, deployment, and services when those are included in the test. It is not replaced by a component test; each layer answers a different scope of question.

Cypress’s component testing documentation describes the component dev-server boundary. Use the narrower test for fast, focused component expectations and retain end-to-end coverage for behavior that depends on the assembled application.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshoot common setup and spec failures

  • The component cannot resolve an alias or plugin. Cypress may not see the application’s full build configuration. Inspect the Vite or Webpack configuration Cypress discovers, then pass the needed configuration or plugin explicitly. For Nuxt, account for aliases and auto-imports because Cypress does not execute nuxt.config. See configuration and the Vue overview.
  • Mount fails before the test reaches its assertion. Check that the configured framework and bundler match the actual project and its Cypress adapter setup. Verify compatibility against the current framework matrix; an unsupported framework may need a community integration through the custom framework mechanism.
  • An Angular component is missing dependencies. Add the required imports, declarations, or providers to the Angular mount setup, and follow the standalone-component guidance where applicable. See Angular examples.
  • A selector assertion fails despite the page rendering. Confirm the queried selector exists in the mounted component, that the expected initial props were passed, and that the interaction targets the intended control. A failure before the implementation is expected only when the spec mounted successfully and the specific behavior is absent.
  • A callback assertion is not met. Verify the spy is passed to the component’s actual callback or event prop and that the asserted argument matches the component’s emitted value. Vue emitted events and React callback props use framework-specific wiring; follow their respective examples.

Or skip the browser setup

For a screenshot of a page rather than an interactive component test, ScreenshotNeo offers a one-request screenshot API and an MCP server. It accepts consent banners as a visitor and removes 60+ known consent platforms, newsletter popups, and chat widgets before capture; those steps can be disabled. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, with response headers indicating the page verdict and billing status.

Example request, as documented at ScreenshotNeo’s API documentation:

curl -G "https://api.screenshotneo.com/v1/shot" 
  -d access_key=YOUR_API_KEY 
  --data-urlencode url=https://stripe.com 
  -o shot.webp

It also provides an MCP server for AI agents, including Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for 1,000 free screenshots a month with no card.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.