Cypress Component Testing 1
Cypress Component Testing 1
Cypress Component Testing provides a component workbench for you to quickly build
and test components from multiple front-end UI libraries — no matter how simple or
complex.
Quick Example
Below is a minimal test to assert that a button component has the correct text:
React
Angular
Vue
Svelte
import Button from './Button'
Learn more about how to test components for React, Angular, Vue, and Svelte.
You can use the browser developer tools to inspect the DOM, play around with
styles, and use the debugger to step through your code.
And since this is Cypress, you get the same APIs, plugins, and ecosystem you are
used to with end-to-end testing to create component tests.
Supported Frameworks
Cypress currently has official mounting libraries for React, Angular, Vue, and
Svelte and support for the following development servers and frameworks:
But in short, Cypress Component Testing uses the same test runner, commands, and
API to test components instead of pages.
The primary difference is that Cypress Component Testing builds your components
using a development server instead of rendering within a complete website, which
results in faster tests and fewer dependencies on infrastructure than end-to-end
tests covering the same code paths.
Cypress's API is user-centric and built for testing anything that renders on the
web. Therefore, many of your tests will appear framework-agnostic and approachable
for developers coming from any background.
For additional reading, we encourage folks to check out the Component Driven
organization, which talks about the pros of component-driven development and may
aid you when trying to figure out if you should be taking a page-based or
component-based approach to building and testing a given feature.