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 desk5 min

How to Test Angular Components with Cypress

Mount Angular components in Cypress’s real browser, provide the right inputs and dependencies, and test rendered behavior and outputs.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Cypress Component Testing to mount an Angular component in a real browser, provide its inputs and dependencies, then interact with it and assert what users can see. The setup runs a development server for the component spec; it does not test the deployed application.

Check Angular compatibility and prerequisites

Cypress’s current Angular overview lists support for Angular ^21.0.0 and ^22.0.0. Compatibility can change, so check the official Angular overview for your project’s versions before setup. The cypress/angular harness requires @angular-devkit/build-angular, including projects that use @angular/build. As of Cypress 16, the harness supports zoneless testing without additional configuration or zone.js; zoneless is the default in Angular 21 and 22.

Component tests answer different questions from class-only and end-to-end tests. Angular notes that class-only tests can validate logic without a DOM, while DOM tests check rendering, response to input, and integration with parent and child components. Cypress mounts the component in a real browser rather than a simulated DOM, as described in its Component Testing guide. Choose the narrowest test environment that can verify the behavior you care about.

Test scope Environment Best suited to
Class-only test No DOM Logic that does not depend on rendering or browser interaction
Cypress component test One component mounted in a real browser Rendered output, user interaction, and component-level integration
End-to-end test The larger application flow Behavior spanning routes, application services, and multiple parts of the app

Install Cypress and enable Component Testing

  1. Install Cypress as a development dependency using your project’s package manager. For npm, run npm install --save-dev cypress.

    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.
  2. Open Cypress with npx cypress open.

  3. Choose Component Testing in the Cypress app. Cypress detects an Angular CLI project and guides you through configuration.

  4. Choose the browser and complete the generated component-testing setup. Cypress uses a development server to compile and serve component specs.

Setup details can vary with the Angular and Cypress versions in your project; follow the generated configuration and the Angular-specific setup guide rather than copying a configuration from a different project style.

Mount a component and make a first assertion

Import the component into a component spec, then call cy.mount(). This minimal test checks that the component renders:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import { StepperComponent } from './stepper.component'

describe('StepperComponent', () => {
  it('mounts', () => {
    cy.mount(StepperComponent)
  })
})

The mount() API yields a wrapper that includes the component and its Angular fixture. After mounting, query the rendered interface, interact with it, and assert visible results. Prefer assertions about user-observable behavior over checks of private implementation details.

Pass inputs, providers, imports, and outputs

Set initial values and dependencies

Supply component values with componentProperties. If a component needs providers, declarations, or imports, pass them in the mount options as appropriate for that component. Standalone components carry imports in their own metadata, so those options do not apply to them in the same way; many standalone components can be mounted directly. Use the setup that matches the component instead of assuming one test-module configuration fits every Angular project.

See Cypress’s Angular examples for the supported mount options and patterns.

Update a legacy @Input() after mounting

For a legacy input that needs to change during the test, use the Angular fixture’s component reference and setInput(). This lets Angular process the input and change detection correctly:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
cy.mount(StepperComponent).then(({ fixture }) => {
  fixture.componentRef.setInput('count', 3)
  fixture.detectChanges()
})

cy.get('[data-cy="count"]').should('have.text', '3')

Replace count and the selector with the input and rendered element used by your component.

Assert output events with a spy

Pass a Cypress spy as the output handler, interact with the component, then verify the emitted value. For example, if the component exposes an output named valueChange:

const onValueChange = cy.spy().as('onValueChange')

cy.mount(StepperComponent, {
  componentProperties: {
    valueChange: onValueChange,
  },
})

cy.get('[data-cy="increment"]').click()
cy.get('@onValueChange').should('have.been.calledWith', 1)

Use a createOutputSpy() helper when that better fits the output pattern in your project. Cypress documents both spy-based output testing and examples for Angular input and model signals in its Angular examples.

Change signal values deliberately

Plain values can provide initial values for Angular input and model signals. If the test needs to change a bound value after mounting, use a writable signal and update it in the test. This distinguishes a one-time initial setup from a value the test intentionally changes later.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Write assertions around user-visible behavior

A component test can verify the same sequence a user experiences: the initial rendered state, an action, and the resulting display or event. For example, a stepper test can check its starting value, click an increment control, and assert both the new displayed value and the output event. Keep test setup focused on the component’s actual collaborators; add providers or imports only when the component requires them.

  • Rendering: assert that expected text or controls appear.
  • Interaction: click, type, or otherwise use the rendered control, then check the resulting state.
  • Inputs: verify that supplied or updated input values affect what the user sees.
  • Outputs: verify that an interaction emits the expected value through the output.
  • Integration: mount with the relevant child components or providers when their interaction is part of the behavior being tested.

Troubleshoot common setup and test failures

  • Angular harness or build setup fails: check that @angular-devkit/build-angular is installed, even if the project uses @angular/build, and review the current Cypress Angular compatibility page.
  • A component import or dependency is missing: confirm whether the component is standalone. For non-standalone components, provide the declarations, imports, or providers it needs through mount options; standalone components generally carry imports in their own metadata.
  • An input update does not produce the expected render: for a legacy @Input(), update it with fixture.componentRef.setInput() rather than assigning a property directly, then allow Angular change detection to run.
  • An output assertion never fires: check that the spy is passed to the correct output property and that the test interacts with the control that emits it.
  • The test expects an application route or deployed page: component testing serves a component spec through a development server; it is not a visit to the deployed staging or production app. Use an end-to-end test for an application-wide route flow.
  • Zoneless configuration causes confusion: Cypress 16 and later supports zoneless testing without extra setup or zone.js; verify the Cypress version and Angular version before applying older configuration advice.

Or skip the browser setup

If your goal is a screenshot of a page rather than an Angular component test, ScreenshotNeo offers a website screenshot API and MCP server. A single GET request returns an image or PDF; for example, save a screenshot of a page as WebP with cURL:

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

See the ScreenshotNeo API documentation for options and authentication. It removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000. Sign up for free.

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.

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.

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
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.