{
  "doc": {
    "id": "app/component-testing/get-started",
    "title": "Component Testing in Cypress | Cypress Documentation",
    "description": "Write Cypress component tests in React, Angular, Vue, or Svelte. Learn how to set up, write, and run your first component test.",
    "section": "app",
    "source_path": "/llm/markdown/app/component-testing/get-started.md",
    "version": "a8fd16711bdda4c7b5645b9717e588ae99ec2470",
    "updated_at": "2026-05-18T17:21:32.047Z",
    "headings": [
      {
        "id": "app/component-testing/get-started#cypress-component-testing",
        "text": "Cypress Component Testing",
        "level": 1
      },
      {
        "id": "app/component-testing/get-started#what-youll-learn",
        "text": "What you'll learn",
        "level": 5
      },
      {
        "id": "app/component-testing/get-started#configuring-component-testing",
        "text": "Configuring Component Testing",
        "level": 2
      },
      {
        "id": "app/component-testing/get-started#supported-frameworks",
        "text": "Supported Frameworks",
        "level": 3
      },
      {
        "id": "app/component-testing/get-started#select-testing-type",
        "text": "Select Testing Type",
        "level": 3
      },
      {
        "id": "app/component-testing/get-started#project-setup",
        "text": "Project Setup",
        "level": 3
      },
      {
        "id": "app/component-testing/get-started#install-dependencies",
        "text": "Install Dependencies",
        "level": 3
      },
      {
        "id": "app/component-testing/get-started#config-files",
        "text": "Config Files",
        "level": 3
      },
      {
        "id": "app/component-testing/get-started#choose-a-browser",
        "text": "Choose A Browser",
        "level": 3
      },
      {
        "id": "app/component-testing/get-started#writing-your-first-test",
        "text": "Writing Your First Test",
        "level": 2
      },
      {
        "id": "app/component-testing/get-started#frameworks",
        "text": "Frameworks",
        "level": 3
      },
      {
        "id": "app/component-testing/get-started#your-first-component-test",
        "text": "Your First Component Test",
        "level": 3
      },
      {
        "id": "app/component-testing/get-started#test-explanation",
        "text": "Test Explanation",
        "level": 3
      },
      {
        "id": "app/component-testing/get-started#running-the-test",
        "text": "Running the Test",
        "level": 2
      },
      {
        "id": "app/component-testing/get-started#selectors-assertions",
        "text": "Selectors & Assertions",
        "level": 3
      },
      {
        "id": "app/component-testing/get-started#passing-props-to-components",
        "text": "Passing Props to Components",
        "level": 3
      },
      {
        "id": "app/component-testing/get-started#testing-interactions",
        "text": "Testing Interactions",
        "level": 3
      },
      {
        "id": "app/component-testing/get-started#testing-components-with-events",
        "text": "Testing Components with Events",
        "level": 2
      },
      {
        "id": "app/component-testing/get-started#using-spies",
        "text": "Using Spies",
        "level": 3
      },
      {
        "id": "app/component-testing/get-started#whats-next",
        "text": "What's Next?",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "app/component-testing/get-started#what-youll-learn",
      "doc_id": "app/component-testing/get-started",
      "heading": "What you'll learn",
      "heading_level": 5,
      "content_markdown": "##### What you'll learn\n\n*   How to set up Component Testing for React, Angular, Vue, or Svelte\n*   How to write your first component test\n*   How to run your component test\n\nAssuming you've successfully [installed Cypress](/llm/markdown/app/get-started/install-cypress.md) and [opened Cypress](/llm/markdown/app/get-started/open-the-app.md), now it's time to setup component testing.\n\nThe Cypress App will guide you through configuring your project.\n",
      "section": "app",
      "anchors": [
        "what-youll-learn"
      ],
      "path": "/llm/json/chunked/app/component-testing/get-started.json",
      "token_estimate": 76
    },
    {
      "id": "app/component-testing/get-started#configuring-component-testing",
      "doc_id": "app/component-testing/get-started",
      "heading": "Configuring Component Testing",
      "heading_level": 2,
      "content_markdown": "## Configuring Component Testing\n\n### Supported Frameworks\n\nCypress currently has official mounting libraries for [React](/llm/markdown/app/component-testing/react/overview.md), [Angular](/llm/markdown/app/component-testing/angular/overview.md), [Vue](/llm/markdown/app/component-testing/vue/overview.md), and [Svelte](/llm/markdown/app/component-testing/svelte/overview.md) and support for the following development servers and frameworks:\n\n| Framework | UI Library | Bundler |\n| --- | --- | --- |\n| [React with Vite](/llm/markdown/app/component-testing/react/overview.md#React-with-Vite) | React 18-19 | Vite 5-8 |\n| [React with Webpack](/llm/markdown/app/component-testing/react/overview.md#React-with-Webpack) | React 18-19 | Webpack 5 |\n| [Next.js 14-16](/llm/markdown/app/component-testing/react/overview.md#Nextjs) | React 18-19 | Webpack 5 |\n| [Vue with Vite](/llm/markdown/app/component-testing/vue/overview.md#Vue-with-Vite) | Vue 3 | Vite 5-8 |\n| [Vue with Webpack](/llm/markdown/app/component-testing/vue/overview.md#Vue-with-Webpack) | Vue 3 | Webpack 5 |\n| [Angular](/llm/markdown/app/component-testing/angular/overview.md#Framework-Configuration) | Angular 18-21 | Webpack 5 |\n| [Svelte with Vite](/llm/markdown/app/component-testing/svelte/overview.md#Svelte-with-Vite) Alpha | Svelte 5 | Vite 5-8 |\n| [Svelte with Webpack](/llm/markdown/app/component-testing/svelte/overview.md#Svelte-with-Webpack) Alpha | Svelte 5 | Webpack 5 |\n\nThe following integrations are built and maintained by Cypress community members.\n\n| Framework | UI Library | Bundler |\n| --- | --- | --- |\n| [Qwik](https://github.com/qwikifiers/cypress-qwik) Community | Qwik | Vite |\n| [Lit](https://github.com/redfox-mx/cypress-lit) Community | Lit | Vite |\n\n### Select Testing Type\n\nWhenever you run Cypress for the first time, the app will prompt you to set up either E2E Testing or Component Testing. Click on \"Component Testing\" to start the configuration wizard.\n\nFor more information on how to choose a testing type, we recommend this [Testing Types Guide](/llm/markdown/app/core-concepts/testing-types.md)\n\nChoose Component Testing\n\n### Project Setup\n\nThe Project Setup screen will automatically detect your framework and bundler. In this example we will use [React](https://react.dev/) and [Vite](https://vitejs.dev/). Click \"Next Step\" to continue.\n\nReact and Vite are automatically detected\n\n### Install Dependencies\n\nThe next screen checks that all the required dependencies are installed. All the items should have green checkboxes on them, indicating everything is good, so click \"Continue\".\n\nAll necessary dependencies are installed\n\n### Config Files\n\nNext, Cypress generates all the necessary configuration files and gives you a list of all the changes it made to your project. Click \"Continue\".\n\nThe Cypress launchpad will scaffold all of these files for you\n\n### Choose A Browser\n\nAfter setting up component testing, you will be at the browser selection screen.\n\nPick the browser of your choice and click the \"Start Component Testing\" button to open the Cypress App.\n\nChoose your browser\n",
      "section": "app",
      "anchors": [
        "configuring-component-testing"
      ],
      "path": "/llm/json/chunked/app/component-testing/get-started.json",
      "token_estimate": 495
    },
    {
      "id": "app/component-testing/get-started#supported-frameworks",
      "doc_id": "app/component-testing/get-started",
      "heading": "Supported Frameworks",
      "heading_level": 3,
      "content_markdown": "### Supported Frameworks\n\nCypress currently has official mounting libraries for [React](/llm/markdown/app/component-testing/react/overview.md), [Angular](/llm/markdown/app/component-testing/angular/overview.md), [Vue](/llm/markdown/app/component-testing/vue/overview.md), and [Svelte](/llm/markdown/app/component-testing/svelte/overview.md) and support for the following development servers and frameworks:\n\n| Framework | UI Library | Bundler |\n| --- | --- | --- |\n| [React with Vite](/llm/markdown/app/component-testing/react/overview.md#React-with-Vite) | React 18-19 | Vite 5-8 |\n| [React with Webpack](/llm/markdown/app/component-testing/react/overview.md#React-with-Webpack) | React 18-19 | Webpack 5 |\n| [Next.js 14-16](/llm/markdown/app/component-testing/react/overview.md#Nextjs) | React 18-19 | Webpack 5 |\n| [Vue with Vite](/llm/markdown/app/component-testing/vue/overview.md#Vue-with-Vite) | Vue 3 | Vite 5-8 |\n| [Vue with Webpack](/llm/markdown/app/component-testing/vue/overview.md#Vue-with-Webpack) | Vue 3 | Webpack 5 |\n| [Angular](/llm/markdown/app/component-testing/angular/overview.md#Framework-Configuration) | Angular 18-21 | Webpack 5 |\n| [Svelte with Vite](/llm/markdown/app/component-testing/svelte/overview.md#Svelte-with-Vite) Alpha | Svelte 5 | Vite 5-8 |\n| [Svelte with Webpack](/llm/markdown/app/component-testing/svelte/overview.md#Svelte-with-Webpack) Alpha | Svelte 5 | Webpack 5 |\n\nThe following integrations are built and maintained by Cypress community members.\n\n| Framework | UI Library | Bundler |\n| --- | --- | --- |\n| [Qwik](https://github.com/qwikifiers/cypress-qwik) Community | Qwik | Vite |\n| [Lit](https://github.com/redfox-mx/cypress-lit) Community | Lit | Vite |\n",
      "section": "app",
      "anchors": [
        "supported-frameworks"
      ],
      "path": "/llm/json/chunked/app/component-testing/get-started.json",
      "token_estimate": 224
    },
    {
      "id": "app/component-testing/get-started#select-testing-type",
      "doc_id": "app/component-testing/get-started",
      "heading": "Select Testing Type",
      "heading_level": 3,
      "content_markdown": "### Select Testing Type\n\nWhenever you run Cypress for the first time, the app will prompt you to set up either E2E Testing or Component Testing. Click on \"Component Testing\" to start the configuration wizard.\n\nFor more information on how to choose a testing type, we recommend this [Testing Types Guide](/llm/markdown/app/core-concepts/testing-types.md)\n\nChoose Component Testing\n",
      "section": "app",
      "anchors": [
        "select-testing-type"
      ],
      "path": "/llm/json/chunked/app/component-testing/get-started.json",
      "token_estimate": 72
    },
    {
      "id": "app/component-testing/get-started#project-setup",
      "doc_id": "app/component-testing/get-started",
      "heading": "Project Setup",
      "heading_level": 3,
      "content_markdown": "### Project Setup\n\nThe Project Setup screen will automatically detect your framework and bundler. In this example we will use [React](https://react.dev/) and [Vite](https://vitejs.dev/). Click \"Next Step\" to continue.\n\nReact and Vite are automatically detected\n",
      "section": "app",
      "anchors": [
        "project-setup"
      ],
      "path": "/llm/json/chunked/app/component-testing/get-started.json",
      "token_estimate": 45
    },
    {
      "id": "app/component-testing/get-started#install-dependencies",
      "doc_id": "app/component-testing/get-started",
      "heading": "Install Dependencies",
      "heading_level": 3,
      "content_markdown": "### Install Dependencies\n\nThe next screen checks that all the required dependencies are installed. All the items should have green checkboxes on them, indicating everything is good, so click \"Continue\".\n\nAll necessary dependencies are installed\n",
      "section": "app",
      "anchors": [
        "install-dependencies"
      ],
      "path": "/llm/json/chunked/app/component-testing/get-started.json",
      "token_estimate": 47
    },
    {
      "id": "app/component-testing/get-started#config-files",
      "doc_id": "app/component-testing/get-started",
      "heading": "Config Files",
      "heading_level": 3,
      "content_markdown": "### Config Files\n\nNext, Cypress generates all the necessary configuration files and gives you a list of all the changes it made to your project. Click \"Continue\".\n\nThe Cypress launchpad will scaffold all of these files for you\n",
      "section": "app",
      "anchors": [
        "config-files"
      ],
      "path": "/llm/json/chunked/app/component-testing/get-started.json",
      "token_estimate": 51
    },
    {
      "id": "app/component-testing/get-started#choose-a-browser",
      "doc_id": "app/component-testing/get-started",
      "heading": "Choose A Browser",
      "heading_level": 3,
      "content_markdown": "### Choose A Browser\n\nAfter setting up component testing, you will be at the browser selection screen.\n\nPick the browser of your choice and click the \"Start Component Testing\" button to open the Cypress App.\n\nChoose your browser\n",
      "section": "app",
      "anchors": [
        "choose-a-browser"
      ],
      "path": "/llm/json/chunked/app/component-testing/get-started.json",
      "token_estimate": 51
    },
    {
      "id": "app/component-testing/get-started#writing-your-first-test",
      "doc_id": "app/component-testing/get-started",
      "heading": "Writing Your First Test",
      "heading_level": 2,
      "content_markdown": "## Writing Your First Test\n\nAt this point, your project is configured to use Cypress Component Testing. However, when the app appears, it won't find any specs because we haven't created any yet. Now we need write our first Component Test.\n\n### Frameworks\n\nCypress currently has official mounting libraries for [React](/llm/markdown/app/component-testing/react/overview.md), [Angular](/llm/markdown/app/component-testing/angular/overview.md), [Vue](/llm/markdown/app/component-testing/vue/overview.md), and [Svelte](/llm/markdown/app/component-testing/svelte/overview.md). In addition to our official framework support there are many community plugins such as [Qwik](https://github.com/qwikifiers/cypress-qwik) and [Lit](https://github.com/redfox-mx/cypress-lit).\n\n### Your First Component Test\n\nThough every framework is different and has its own unique nuances, in general, writing tests is very similar. Let's look at how a basic test is written for a `StepperComponent`.\n\nLet's assume the Stepper Component consists of two `buttons`, one used to **decrement** the counter and one to **increment** it as well as a `span` tag that sits in the middle of the buttons to show the current value of the counter.\n\nTo see examples of the Stepper Component and its tests in each Framework, visit our [Component Testing Quick Start Apps Repo](https://github.com/cypress-io/component-testing-quickstart-apps)\n\n*   React\n*   Angular\n*   Vue\n*   Svelte\n\n```\nimport React from 'react'import Stepper from './Stepper'describe('<Stepper />', () => {  it('mounts', () => {    // see: https://on.cypress.io/mounting-react    cy.mount(<Stepper />)  })})\n```\n\n```\nimport { StepperComponent } from './stepper.component'describe('StepperComponent', () => {  it('mounts', () => {    // see: https://on.cypress.io/mounting-angular    cy.mount(StepperComponent)  })})\n```\n\n```\nimport Stepper from './Stepper.vue'describe('<Stepper />', () => {  it('mounts', () => {    // see: https://on.cypress.io/mounting-vue    cy.mount(Stepper)  })})\n```\n\n```\nimport Stepper from './Stepper.svelte'describe('Stepper', () => {  it('mounts', () => {    // see: https://on.cypress.io/mounting-svelte    cy.mount(Stepper)  })})\n```\n\n### Test Explanation\n\nLet's break down the spec. First, we import the `Stepper` component. Then, we organize our tests using the functions `describe` and `it`, which allows us to group tests into sections by using method blocks. These are global functions provided by Cypress, which means you don't have to import them directly to use them. The top-level `describe` block will be the container for all our tests in a file, and each `it` represents an individual test. The `describe` function takes two parameters, the first of which is the name of the test suite, and the second is a function that will execute the tests.\n\nWe defined a test using the `it` function inside `describe`. The first parameter to `it` is a brief description of the spec, and the second parameter is a function that contains the test code. In our example above, we only have one test, but soon we'll see how we can add multiple `it` blocks inside of a `describe` for a series of tests.\n\nThe [cy.mount()](/llm/markdown/api/commands/mount.md) method will mount our component into the test app so we can begin running tests against it.\n\nNow it's time to see the test in action.\n",
      "section": "app",
      "anchors": [
        "writing-your-first-test"
      ],
      "path": "/llm/json/chunked/app/component-testing/get-started.json",
      "token_estimate": 607
    },
    {
      "id": "app/component-testing/get-started#frameworks",
      "doc_id": "app/component-testing/get-started",
      "heading": "Frameworks",
      "heading_level": 3,
      "content_markdown": "### Frameworks\n\nCypress currently has official mounting libraries for [React](/llm/markdown/app/component-testing/react/overview.md), [Angular](/llm/markdown/app/component-testing/angular/overview.md), [Vue](/llm/markdown/app/component-testing/vue/overview.md), and [Svelte](/llm/markdown/app/component-testing/svelte/overview.md). In addition to our official framework support there are many community plugins such as [Qwik](https://github.com/qwikifiers/cypress-qwik) and [Lit](https://github.com/redfox-mx/cypress-lit).\n",
      "section": "app",
      "anchors": [
        "frameworks"
      ],
      "path": "/llm/json/chunked/app/component-testing/get-started.json",
      "token_estimate": 41
    },
    {
      "id": "app/component-testing/get-started#your-first-component-test",
      "doc_id": "app/component-testing/get-started",
      "heading": "Your First Component Test",
      "heading_level": 3,
      "content_markdown": "### Your First Component Test\n\nThough every framework is different and has its own unique nuances, in general, writing tests is very similar. Let's look at how a basic test is written for a `StepperComponent`.\n\nLet's assume the Stepper Component consists of two `buttons`, one used to **decrement** the counter and one to **increment** it as well as a `span` tag that sits in the middle of the buttons to show the current value of the counter.\n\nTo see examples of the Stepper Component and its tests in each Framework, visit our [Component Testing Quick Start Apps Repo](https://github.com/cypress-io/component-testing-quickstart-apps)\n\n*   React\n*   Angular\n*   Vue\n*   Svelte\n\n```\nimport React from 'react'import Stepper from './Stepper'describe('<Stepper />', () => {  it('mounts', () => {    // see: https://on.cypress.io/mounting-react    cy.mount(<Stepper />)  })})\n```\n\n```\nimport { StepperComponent } from './stepper.component'describe('StepperComponent', () => {  it('mounts', () => {    // see: https://on.cypress.io/mounting-angular    cy.mount(StepperComponent)  })})\n```\n\n```\nimport Stepper from './Stepper.vue'describe('<Stepper />', () => {  it('mounts', () => {    // see: https://on.cypress.io/mounting-vue    cy.mount(Stepper)  })})\n```\n\n```\nimport Stepper from './Stepper.svelte'describe('Stepper', () => {  it('mounts', () => {    // see: https://on.cypress.io/mounting-svelte    cy.mount(Stepper)  })})\n```\n",
      "section": "app",
      "anchors": [
        "your-first-component-test"
      ],
      "path": "/llm/json/chunked/app/component-testing/get-started.json",
      "token_estimate": 248
    },
    {
      "id": "app/component-testing/get-started#test-explanation",
      "doc_id": "app/component-testing/get-started",
      "heading": "Test Explanation",
      "heading_level": 3,
      "content_markdown": "### Test Explanation\n\nLet's break down the spec. First, we import the `Stepper` component. Then, we organize our tests using the functions `describe` and `it`, which allows us to group tests into sections by using method blocks. These are global functions provided by Cypress, which means you don't have to import them directly to use them. The top-level `describe` block will be the container for all our tests in a file, and each `it` represents an individual test. The `describe` function takes two parameters, the first of which is the name of the test suite, and the second is a function that will execute the tests.\n\nWe defined a test using the `it` function inside `describe`. The first parameter to `it` is a brief description of the spec, and the second parameter is a function that contains the test code. In our example above, we only have one test, but soon we'll see how we can add multiple `it` blocks inside of a `describe` for a series of tests.\n\nThe [cy.mount()](/llm/markdown/api/commands/mount.md) method will mount our component into the test app so we can begin running tests against it.\n\nNow it's time to see the test in action.\n",
      "section": "app",
      "anchors": [
        "test-explanation"
      ],
      "path": "/llm/json/chunked/app/component-testing/get-started.json",
      "token_estimate": 263
    },
    {
      "id": "app/component-testing/get-started#running-the-test",
      "doc_id": "app/component-testing/get-started",
      "heading": "Running the Test",
      "heading_level": 2,
      "content_markdown": "## Running the Test\n\nSwitch back to the browser you opened for testing, and you should now see the `Stepper` Component in the spec list. Click it to see the spec execute.\n\nOur first test verifies the component can mount in its default state without any errors. If there is a runtime error during test execution, the test will fail, and you will see a stack trace pointing to the source of the problem.\n\nA basic test like the one above is an excellent way to start testing a component. Cypress renders your component in a real browser, and you can use all the techniques/tools you would normally during development, such as interacting with the component in the test runner, and using the browser dev tools to inspect and debug both your tests and the component's code.\n\nFeel free to play around with the `Stepper` component by interacting with the increment and decrement buttons.\n\nNow that the component is mounted, our next step is to test that the behavior of the component is correct.\n\n### Selectors & Assertions\n\nBy default, the Stepper's counter is initialized to \"0\". We can override that value by specifying an initial count. Let's write a couple of tests that will verify both these states.\n\nTo do so, we will use a selector to access the `span` element that contains the counter, and then assert that the text value of the element is what we expect it to be.\n\nThere are various ways to select items from the DOM using Cypress. We will use [cy.get()](/llm/markdown/api/commands/get.md), which allows us to pass in a CSS-like selector.\n\nAfter we \"get\" the element, we use the [should](/llm/markdown/api/commands/should.md) assertion method to verify it has the correct text value.\n\nAdd the following test inside the `describe` block, right below the first test:\n\n*   React\n*   Angular\n*   Vue\n*   Svelte\n\n```\nit('stepper should default to 0', () => {  cy.mount(<Stepper />)  cy.get('span').should('have.text', '0')})\n```\n\n```\nit('stepper should default to 0', () => {  cy.mount(StepperComponent)  cy.get('span').should('have.text', '0')})\n```\n\n```\nit('stepper should default to 0', () => {  cy.mount(Stepper)  cy.get('span').should('have.text', '0')})\n```\n\n```\nit('stepper should default to 0', () => {  cy.mount(Stepper)  cy.get('span').should('have.text', '0')})\n```\n\nWhen you go back to the test runner, you should see the test pass.\n\nIn the above test, we select the element by passing in \"span\" to `cy.get()`, which will select all `span` tags in our component. We only have one `span` currently, so this works. However, if our component evolves and we add another `span`, then this test could start to fail. We should use a selector that will be less brittle to future changes.\n\nIn the `Stepper` component, the `span` tag has a `data-cy` attribute on it:\n\n*   React\n*   Angular\n*   Vue\n*   Svelte\n\n```\n<span data-cy=\"counter\">{count}</span>\n```\n\n```\n<span data-cy=\"counter\">{{ count }}</span>\n```\n\n```\n<span data-cy=\"counter\">{{ count }}</span>\n```\n\n```\n<span data-cy=\"counter\">{count}</span>\n```\n\nWe assign a unique id to the `data-cy` attribute that we can use for testing purposes. Update the test to use a CSS attribute selector to `cy.get()`:\n\n*   React\n*   Angular\n*   Vue\n*   Svelte\n\n```\nit('stepper should default to 0', () => {  cy.mount(<Stepper />)  cy.get('[data-cy=counter]').should('have.text', '0')})\n```\n\n```\nit('stepper should default to 0', () => {  cy.mount(StepperComponent)  cy.get('[data-cy=counter]').should('have.text', '0')})\n```\n\n```\nit('stepper should default to 0', () => {  cy.mount(Stepper)  cy.get('[data-cy=counter]').should('have.text', '0')})\n```\n\n```\nit('stepper should default to 0', () => {  cy.mount(Stepper)  cy.get('[data-cy=counter]').should('have.text', '0')})\n```\n\nThe test will still pass as expected, and our selector is now future-proof. For more info on writing good selectors, see our guide [Selector Best Practices](/llm/markdown/app/core-concepts/best-practices.md#Selecting-Elements).\n\n### Passing Props to Components\n\nWe should also have a test to ensure the `count` prop sets the count to something else besides its default value of \"0\". We can pass in props to the `Stepper` component like so:\n\n*   React\n*   Angular\n*   Vue\n*   Svelte\n\n```\nit('supports a \"count\" prop to set the value', () => {  cy.mount(<Stepper count={100} />)  cy.get('[data-cy=counter]').should('have.text', '100')})\n```\n\n```\nit('supports a \"count\" prop to set the value', () => {  cy.mount(StepperComponent, {    componentProperties: {      count: 100,    },  })  cy.get('[data-cy=counter]').should('have.text', '100')})\n```\n\n```\nit('supports a \"count\" prop to set the value', () => {  cy.mount(Stepper, { props: { count: 100 } })  cy.get('[data-cy=counter]').should('have.text', '100')})\n```\n\n```\nit('supports a \"count\" prop to set the value', () => {  cy.mount(Stepper, { props: { count: 100 } })  cy.get('[data-cy=counter]').should('have.text', '100')})\n```\n\n### Testing Interactions\n\nWe mounted and selected the element in the above tests but didn't interact with it. We should also test that the value of the counter changes when a user clicks the \"increment\" and \"decrement\" buttons.\n\nTo do so, we will interact with the component by using the [click()](/llm/markdown/api/commands/click.md) command, which clicks a DOM element just like a real user would.\n\nAdd the following tests:\n\n*   React\n*   Angular\n*   Vue\n*   Svelte\n\n```\nit('when the increment button is pressed, the counter is incremented', () => {  cy.mount(<Stepper />)  cy.get('[data-cy=increment]').click()  cy.get('[data-cy=counter]').should('have.text', '1')})it('when the decrement button is pressed, the counter is decremented', () => {  cy.mount(<Stepper />)  cy.get('[data-cy=decrement]').click()  cy.get('[data-cy=counter]').should('have.text', '-1')})\n```\n\n```\nit('when the increment button is pressed, the counter is incremented', () => {  cy.mount(StepperComponent)  cy.get('[data-cy=increment]').click()  cy.get('[data-cy=counter]').should('have.text', '1')})it('when the decrement button is pressed, the counter is decremented', () => {  cy.mount(StepperComponent)  cy.get('[data-cy=decrement]').click()  cy.get('[data-cy=counter]').should('have.text', '-1')})\n```\n\n```\nit('when the increment button is pressed, the counter is incremented', () => {  cy.mount(Stepper)  cy.get('[data-cy=increment]').click()  cy.get('[data-cy=counter]').should('have.text', '1')})it('when the decrement button is pressed, the counter is decremented', () => {  cy.mount(Stepper)  cy.get('[data-cy=decrement]').click()  cy.get('[data-cy=counter]').should('have.text', '-1')})\n```\n\n```\nit('when the increment button is pressed, the counter is incremented', () => {  cy.mount(Stepper)  cy.get('[data-cy=increment]').click()  cy.get('[data-cy=counter]').should('have.text', '1')})it('when the decrement button is pressed, the counter is decremented', () => {  cy.mount(Stepper)  cy.get('[data-cy=decrement]').click()  cy.get('[data-cy=counter]').should('have.text', '-1')})\n```\n\nWhen you view the results of each of the tests, you will see that the counter is now \"1\" in the **increment** test, and \"-1\" in the **decrement** test. Not only did our tests pass, but we can visually see the results in a browser!\n",
      "section": "app",
      "anchors": [
        "running-the-test"
      ],
      "path": "/llm/json/chunked/app/component-testing/get-started.json",
      "token_estimate": 1317
    },
    {
      "id": "app/component-testing/get-started#selectors-assertions",
      "doc_id": "app/component-testing/get-started",
      "heading": "Selectors & Assertions",
      "heading_level": 3,
      "content_markdown": "### Selectors & Assertions\n\nBy default, the Stepper's counter is initialized to \"0\". We can override that value by specifying an initial count. Let's write a couple of tests that will verify both these states.\n\nTo do so, we will use a selector to access the `span` element that contains the counter, and then assert that the text value of the element is what we expect it to be.\n\nThere are various ways to select items from the DOM using Cypress. We will use [cy.get()](/llm/markdown/api/commands/get.md), which allows us to pass in a CSS-like selector.\n\nAfter we \"get\" the element, we use the [should](/llm/markdown/api/commands/should.md) assertion method to verify it has the correct text value.\n\nAdd the following test inside the `describe` block, right below the first test:\n\n*   React\n*   Angular\n*   Vue\n*   Svelte\n\n```\nit('stepper should default to 0', () => {  cy.mount(<Stepper />)  cy.get('span').should('have.text', '0')})\n```\n\n```\nit('stepper should default to 0', () => {  cy.mount(StepperComponent)  cy.get('span').should('have.text', '0')})\n```\n\n```\nit('stepper should default to 0', () => {  cy.mount(Stepper)  cy.get('span').should('have.text', '0')})\n```\n\n```\nit('stepper should default to 0', () => {  cy.mount(Stepper)  cy.get('span').should('have.text', '0')})\n```\n\nWhen you go back to the test runner, you should see the test pass.\n\nIn the above test, we select the element by passing in \"span\" to `cy.get()`, which will select all `span` tags in our component. We only have one `span` currently, so this works. However, if our component evolves and we add another `span`, then this test could start to fail. We should use a selector that will be less brittle to future changes.\n\nIn the `Stepper` component, the `span` tag has a `data-cy` attribute on it:\n\n*   React\n*   Angular\n*   Vue\n*   Svelte\n\n```\n<span data-cy=\"counter\">{count}</span>\n```\n\n```\n<span data-cy=\"counter\">{{ count }}</span>\n```\n\n```\n<span data-cy=\"counter\">{{ count }}</span>\n```\n\n```\n<span data-cy=\"counter\">{count}</span>\n```\n\nWe assign a unique id to the `data-cy` attribute that we can use for testing purposes. Update the test to use a CSS attribute selector to `cy.get()`:\n\n*   React\n*   Angular\n*   Vue\n*   Svelte\n\n```\nit('stepper should default to 0', () => {  cy.mount(<Stepper />)  cy.get('[data-cy=counter]').should('have.text', '0')})\n```\n\n```\nit('stepper should default to 0', () => {  cy.mount(StepperComponent)  cy.get('[data-cy=counter]').should('have.text', '0')})\n```\n\n```\nit('stepper should default to 0', () => {  cy.mount(Stepper)  cy.get('[data-cy=counter]').should('have.text', '0')})\n```\n\n```\nit('stepper should default to 0', () => {  cy.mount(Stepper)  cy.get('[data-cy=counter]').should('have.text', '0')})\n```\n\nThe test will still pass as expected, and our selector is now future-proof. For more info on writing good selectors, see our guide [Selector Best Practices](/llm/markdown/app/core-concepts/best-practices.md#Selecting-Elements).\n",
      "section": "app",
      "anchors": [
        "selectors-assertions"
      ],
      "path": "/llm/json/chunked/app/component-testing/get-started.json",
      "token_estimate": 557
    },
    {
      "id": "app/component-testing/get-started#passing-props-to-components",
      "doc_id": "app/component-testing/get-started",
      "heading": "Passing Props to Components",
      "heading_level": 3,
      "content_markdown": "### Passing Props to Components\n\nWe should also have a test to ensure the `count` prop sets the count to something else besides its default value of \"0\". We can pass in props to the `Stepper` component like so:\n\n*   React\n*   Angular\n*   Vue\n*   Svelte\n\n```\nit('supports a \"count\" prop to set the value', () => {  cy.mount(<Stepper count={100} />)  cy.get('[data-cy=counter]').should('have.text', '100')})\n```\n\n```\nit('supports a \"count\" prop to set the value', () => {  cy.mount(StepperComponent, {    componentProperties: {      count: 100,    },  })  cy.get('[data-cy=counter]').should('have.text', '100')})\n```\n\n```\nit('supports a \"count\" prop to set the value', () => {  cy.mount(Stepper, { props: { count: 100 } })  cy.get('[data-cy=counter]').should('have.text', '100')})\n```\n\n```\nit('supports a \"count\" prop to set the value', () => {  cy.mount(Stepper, { props: { count: 100 } })  cy.get('[data-cy=counter]').should('have.text', '100')})\n```\n",
      "section": "app",
      "anchors": [
        "passing-props-to-components"
      ],
      "path": "/llm/json/chunked/app/component-testing/get-started.json",
      "token_estimate": 179
    },
    {
      "id": "app/component-testing/get-started#testing-interactions",
      "doc_id": "app/component-testing/get-started",
      "heading": "Testing Interactions",
      "heading_level": 3,
      "content_markdown": "### Testing Interactions\n\nWe mounted and selected the element in the above tests but didn't interact with it. We should also test that the value of the counter changes when a user clicks the \"increment\" and \"decrement\" buttons.\n\nTo do so, we will interact with the component by using the [click()](/llm/markdown/api/commands/click.md) command, which clicks a DOM element just like a real user would.\n\nAdd the following tests:\n\n*   React\n*   Angular\n*   Vue\n*   Svelte\n\n```\nit('when the increment button is pressed, the counter is incremented', () => {  cy.mount(<Stepper />)  cy.get('[data-cy=increment]').click()  cy.get('[data-cy=counter]').should('have.text', '1')})it('when the decrement button is pressed, the counter is decremented', () => {  cy.mount(<Stepper />)  cy.get('[data-cy=decrement]').click()  cy.get('[data-cy=counter]').should('have.text', '-1')})\n```\n\n```\nit('when the increment button is pressed, the counter is incremented', () => {  cy.mount(StepperComponent)  cy.get('[data-cy=increment]').click()  cy.get('[data-cy=counter]').should('have.text', '1')})it('when the decrement button is pressed, the counter is decremented', () => {  cy.mount(StepperComponent)  cy.get('[data-cy=decrement]').click()  cy.get('[data-cy=counter]').should('have.text', '-1')})\n```\n\n```\nit('when the increment button is pressed, the counter is incremented', () => {  cy.mount(Stepper)  cy.get('[data-cy=increment]').click()  cy.get('[data-cy=counter]').should('have.text', '1')})it('when the decrement button is pressed, the counter is decremented', () => {  cy.mount(Stepper)  cy.get('[data-cy=decrement]').click()  cy.get('[data-cy=counter]').should('have.text', '-1')})\n```\n\n```\nit('when the increment button is pressed, the counter is incremented', () => {  cy.mount(Stepper)  cy.get('[data-cy=increment]').click()  cy.get('[data-cy=counter]').should('have.text', '1')})it('when the decrement button is pressed, the counter is decremented', () => {  cy.mount(Stepper)  cy.get('[data-cy=decrement]').click()  cy.get('[data-cy=counter]').should('have.text', '-1')})\n```\n\nWhen you view the results of each of the tests, you will see that the counter is now \"1\" in the **increment** test, and \"-1\" in the **decrement** test. Not only did our tests pass, but we can visually see the results in a browser!\n",
      "section": "app",
      "anchors": [
        "testing-interactions"
      ],
      "path": "/llm/json/chunked/app/component-testing/get-started.json",
      "token_estimate": 349
    },
    {
      "id": "app/component-testing/get-started#testing-components-with-events",
      "doc_id": "app/component-testing/get-started",
      "heading": "Testing Components with Events",
      "heading_level": 2,
      "content_markdown": "## Testing Components with Events\n\nAll the state of the `Stepper` Component (ie: the count) is handled internally in the component and then consumers are then alerted to changes to the state.\n\nAs the developer of the `Stepper` Component, you want to make sure when the end-user clicks the **increment** and **decrement** buttons, that the appropriate event is triggered with the proper values in the consuming component.\n\n### Using Spies\n\nWe can use [Cypress Spies](/llm/markdown/app/guides/stubs-spies-and-clocks.md#Spies) to validate these events are being called correctly. A spy is a special function that keeps track of how many times it was called and any parameters that it was called with. We can then assign a spy to our event, interact with the component, and then query the spy to validate it was called with the parameters we expect.\n\nLet's set up the spies and bind them to the component:\n\n*   React\n*   Angular\n*   Vue\n*   Svelte\n\n```\nit('clicking + fires a change event with the incremented value', () => {  const onChangeSpy = cy.spy().as('onChangeSpy')  cy.mount(<Stepper onChange={onChangeSpy} />)  cy.get('[data-cy=increment]').click()  cy.get('@onChangeSpy').should('have.been.calledWith', 1)})\n```\n\n```\nit('clicking + fires a change event with the incremented value', () => {  const onChangeSpy = cy.spy().as('onChangeSpy')  cy.mount(StepperComponent, {    componentProperties: {      change: {        emit: onChangeSpy,      } as any,    },  })  cy.get('[data-cy=increment]').click()  cy.get('@changeSpy').should('have.been.calledWith', 1)})\n```\n\n```\nit('clicking + fires a change event with the incremented value', () => {  const onChangeSpy = cy.spy().as('onChangeSpy')  cy.mount(Stepper, { props: { onChange: onChangeSpy } })  cy.get('[data-cy=increment]').click()  cy.get('@onChangeSpy').should('have.been.calledWith', 1)})\n```\n\n```\nit('clicking + fires a change event with the incremented value', () => {  const onChangeSpy = cy.spy().as('onChangeSpy')  cy.mount(Stepper, { props: { onChange: onChangeSpy } })  cy.get('[data-cy=increment]').click()  cy.get('@onChangeSpy').should('have.been.calledWith', 1)})\n```\n\nFirst, we create a new spy by calling the `cy.spy()` method. We pass in a string that gives the spy an [alias](/llm/markdown/app/core-concepts/variables-and-aliases.md), which assigns the spy a name by which we can reference it later. In `cy.mount()`, we initialize the component and pass the spy into it. After that, we click the increment button.\n\nThe next line is a bit different. We've seen how we can use the `cy.get()` method to select elements, but we can also use it to grab any aliases we've set up previously. We use `cy.get()` to grab the alias to the spy (by prepending an \"@\" to the alias name). We assert that the method was called with the expected value.\n\nWith that, the `Stepper` component is well tested. Nice job!\n",
      "section": "app",
      "anchors": [
        "testing-components-with-events"
      ],
      "path": "/llm/json/chunked/app/component-testing/get-started.json",
      "token_estimate": 533
    },
    {
      "id": "app/component-testing/get-started#using-spies",
      "doc_id": "app/component-testing/get-started",
      "heading": "Using Spies",
      "heading_level": 3,
      "content_markdown": "### Using Spies\n\nWe can use [Cypress Spies](/llm/markdown/app/guides/stubs-spies-and-clocks.md#Spies) to validate these events are being called correctly. A spy is a special function that keeps track of how many times it was called and any parameters that it was called with. We can then assign a spy to our event, interact with the component, and then query the spy to validate it was called with the parameters we expect.\n\nLet's set up the spies and bind them to the component:\n\n*   React\n*   Angular\n*   Vue\n*   Svelte\n\n```\nit('clicking + fires a change event with the incremented value', () => {  const onChangeSpy = cy.spy().as('onChangeSpy')  cy.mount(<Stepper onChange={onChangeSpy} />)  cy.get('[data-cy=increment]').click()  cy.get('@onChangeSpy').should('have.been.calledWith', 1)})\n```\n\n```\nit('clicking + fires a change event with the incremented value', () => {  const onChangeSpy = cy.spy().as('onChangeSpy')  cy.mount(StepperComponent, {    componentProperties: {      change: {        emit: onChangeSpy,      } as any,    },  })  cy.get('[data-cy=increment]').click()  cy.get('@changeSpy').should('have.been.calledWith', 1)})\n```\n\n```\nit('clicking + fires a change event with the incremented value', () => {  const onChangeSpy = cy.spy().as('onChangeSpy')  cy.mount(Stepper, { props: { onChange: onChangeSpy } })  cy.get('[data-cy=increment]').click()  cy.get('@onChangeSpy').should('have.been.calledWith', 1)})\n```\n\n```\nit('clicking + fires a change event with the incremented value', () => {  const onChangeSpy = cy.spy().as('onChangeSpy')  cy.mount(Stepper, { props: { onChange: onChangeSpy } })  cy.get('[data-cy=increment]').click()  cy.get('@onChangeSpy').should('have.been.calledWith', 1)})\n```\n\nFirst, we create a new spy by calling the `cy.spy()` method. We pass in a string that gives the spy an [alias](/llm/markdown/app/core-concepts/variables-and-aliases.md), which assigns the spy a name by which we can reference it later. In `cy.mount()`, we initialize the component and pass the spy into it. After that, we click the increment button.\n\nThe next line is a bit different. We've seen how we can use the `cy.get()` method to select elements, but we can also use it to grab any aliases we've set up previously. We use `cy.get()` to grab the alias to the spy (by prepending an \"@\" to the alias name). We assert that the method was called with the expected value.\n\nWith that, the `Stepper` component is well tested. Nice job!\n",
      "section": "app",
      "anchors": [
        "using-spies"
      ],
      "path": "/llm/json/chunked/app/component-testing/get-started.json",
      "token_estimate": 444
    },
    {
      "id": "app/component-testing/get-started#whats-next",
      "doc_id": "app/component-testing/get-started",
      "heading": "What's Next?",
      "heading_level": 2,
      "content_markdown": "## What's Next?\n\nCongratulations, you covered the basics for Component Testing with Cypress!\n\nTo learn more about testing with Cypress, check out the [Introduction to Cypress](/llm/markdown/app/core-concepts/introduction-to-cypress.md) guide.\n\nWriting component tests with an AI coding tool? The `/cypress-author` skill applies Cypress best practices automatically. See [Cypress AI Skills](/llm/markdown/app/tooling/ai-skills.md).\n",
      "section": "app",
      "anchors": [
        "whats-next"
      ],
      "path": "/llm/json/chunked/app/component-testing/get-started.json",
      "token_estimate": 63
    }
  ]
}