Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober 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 desk4 min

Cypress React Component Testing: Setup, Mounting, and Test Boundaries

Mount React components in a real browser with Cypress, configure the component dev server, and understand when a Next.js page needs end-to-end coverage.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Cypress Component Testing lets you mount a React component in a real browser, then exercise and assert on the rendered UI with Cypress commands. To get started, configure Cypress’s component dev server for React and your bundler, import the component, and call cy.mount(<Component />). The current Cypress React overview documents React 18 and 19 with Vite 8 or Webpack 5, plus Next.js 15 and 16 using Webpack; check the current support overview before upgrading because compatibility can change.

What Cypress React Component Testing does

Component tests render a component directly in a real browser rather than a simulated DOM. You interact with the mounted UI and make assertions using Cypress commands. That gives you a focused way to check a component’s visible state and behavior without making every test depend on a full application flow. Cypress describes this as mounting components “directly in a real browser — not a simulated DOM.” (Cypress Component Testing: Getting Started)

What React setups are documented

Cypress’s React overview lists React 18 and 19, React with Vite 8, React with Webpack 5, and Next.js 15 or 16 with Webpack. These are the combinations documented by the overview, not a guarantee that every later or custom configuration is supported. Confirm the live compatibility guidance when changing major versions or bundlers.

Setup Documented combination
React + Vite React 18 or 19 with Vite 8
React + Webpack React 18 or 19 with Webpack 5
Next.js Next.js 15 or 16 using Webpack

For the documented React/Webpack path, Cypress lists Cypress, React, React DOM, and Webpack 5 as requirements. Cypress says the React mount adapter and Webpack dev server are bundled in the Cypress package for this path, so separate installation of those pieces is generally unnecessary. See the React overview for its current details.

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

Set up the component dev server

The key configuration is component.devServer, where you identify the UI framework and bundler. For React with Vite, the shape is { framework: 'react', bundler: 'vite' }; for Webpack, use bundler: 'webpack'. Cypress’s setup flow can detect supported project tooling, check dependencies, and scaffold configuration through Launchpad. The generated component configuration names the framework and bundler explicitly. See Getting Started and the configuration reference.

A minimal configuration shape is:

component: {
  devServer: {
    framework: 'react',
    bundler: 'vite'
  }
}

Replace vite with webpack when that is your bundler. Cypress searches upward from the project root for the relevant Vite or Webpack configuration when an explicit configuration override is omitted. If the project needs a different configuration, the override can be an object or an asynchronous function that returns a config, as described in the configuration reference.

Write a first component test

  1. Import the component into a Cypress component spec.

  2. Mount it by passing JSX to cy.mount(), for example cy.mount(<Stepper />).

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  3. Use a stable selector such as a data-cy attribute to find the relevant element.

  4. Interact with the rendered UI if needed, then assert the expected result.

A minimal example, following Cypress’s documented pattern, might look like this:

import Stepper from './Stepper'

describe('Stepper', () => {
  it('renders and responds to a click', () => {
    cy.mount(<Stepper />)
    cy.get('[data-cy=counter]').should('have.text', '0')
    cy.get('[data-cy=increment]').click()
    cy.get('[data-cy=counter]').should('have.text', '1')
  })
})

The exact selectors and expected values depend on your component. Cypress’s React guide also shows that props belong directly in the JSX passed to the mount call, such as cy.mount(<Stepper initial={100} />). Refer to React component testing examples for the documented mounting and assertion API.

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

Share providers and other common setup

If components depend on shared context—such as a router, theme, or state provider—create a customized cy.mount() command in the component support file that wraps the node in the required providers. This avoids repeating wrapper setup in each spec. The React mount API also describes mount options such as strict rendering and provides a rerender function through the returned Cypress chainable. Use those features when the test specifically needs them; the standard starting point remains mounting the component with the props and context it needs. See the React API and Cypress FAQ.

Choose component tests or end-to-end tests for Next.js

Use component tests for individual React components. For a Next.js page that relies on server-only getServerSideProps or getStaticProps, Cypress recommends end-to-end testing: those methods run on the server and are not available in a component test. Manually supplying props to a mounted page can test how the page renders with those props, but it does not exercise the server data-loading method. Cypress explains this distinction in its React overview.

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

What to cover in a component spec

Cypress’s examples establish the mounting, props, event-handler, and assertion patterns; they do not prescribe a mandatory checklist. A useful way to organize your own coverage is to consider:

Keep the test focused on the component’s contract. If the behavior depends on server execution, route navigation across the app, or other full-application wiring, choose an end-to-end test instead.

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.

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.

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. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.