---
id: api/commands/mount
title: cy.mount()
description: >-
  Render a component in Cypress Component Testing with cy.mount(), a custom
  command you register in your component support file.
section: api
source_path: docs/api/commands/mount.mdx
version: c4ad6f88c531de58221c73dd91a75af7138334b8
updated_at: '2026-11-10T01:15:02.829Z'
---
# mount

`cy.mount()` renders a component in a real browser, so your component tests run against the same DOM, CSS, and browser APIs your users get instead of a simulated DOM in Node.js. Cypress reserves the command name but doesn't implement it, because each framework renders components differently. When you set up Component Testing, Cypress scaffolds `cy.mount()` in your component support file, using the `mount()` function from your framework's mounting library.

If you arrived here from the "`cy.mount()` must be implemented by the user" error, go to [the fix for that error](#cymount-must-be-implemented-by-the-user).

## Syntax

```
cy.mount(component)
cy.mount(component, options)
```

### Arguments

**component**

The component to render, in the form your framework's `mount()` takes:

*   Angular: a component class, or a template string
*   React: a JSX element, such as `<Stepper />`
*   Svelte: a Svelte component
*   Vue: a Vue component

**options _(Object)_**

Options for your framework's `mount()`, such as props, plus any options your custom command adds. Each framework's API page lists its options:

*   [Angular API](/llm/markdown/app/component-testing/angular/api.md)
*   [React API](/llm/markdown/app/component-testing/react/api.md)
*   [Svelte API](/llm/markdown/app/component-testing/svelte/api.md)
*   [Vue API](/llm/markdown/app/component-testing/vue/api.md)

### Yields

`cy.mount()` yields whatever your framework's `mount()` returns:

| Framework | Yields | Use it to |
| --- | --- | --- |
| Angular | `{ component, fixture }` | Read the component instance, or work with its `ComponentFixture` |
| React | `{ component, rerender }` | Rerender the component with new props (see [Remount and rerender](#Remount-and-rerender-components-with-cymount)) |
| Svelte | `{ component }` | Call functions and read values the component exports |
| Vue | `{ component, wrapper }` | Read the component instance, or use the Vue Test Utils wrapper's methods |

## Create a new `cy.mount()` command

When you configure Component Testing through the Cypress App, Cypress scaffolds the command for you in `cypress/support/component.js` (or `cypress/support/component.ts`), so most projects start with a working `cy.mount()` that you can customize from there.

We recommend registering a custom `cy.mount()` command instead of importing the mount function from the mounting libraries in each spec. Doing so offers a few advantages:

*   You don't need to import the mount function into every spec, since `cy.mount()` is available globally.
*   You set up what every test needs in one place, such as wrapping a component in a [React context provider](https://react.dev/learn/passing-data-deeply-with-context) or adding [Vue plugins](https://vuejs.org/guide/reusability/plugins.html).

To use `cy.mount()`, add a custom command with [`Cypress.Commands.add()`](/llm/markdown/api/cypress-api/custom-commands.md) in your component support file. The file only loads for component tests, so your end-to-end tests don't bundle a mounting library they never use. Start from one of these examples:

*   React
*   Angular
*   Vue
*   Svelte

cypress/support/component.js

```
import { mount } from 'cypress/react'

Cypress.Commands.add('mount', (component, options) => {
  // Rename this file to .jsx to wrap the component in providers:
  // return mount(<MyProvider>{component}</MyProvider>, options)
  return mount(component, options)
})
```

cypress/support/component.js

```
import { mount } from 'cypress/angular'

Cypress.Commands.add('mount', (component, config) => {
  return mount(component, config)
})
```

cypress/support/component.js

```
import { mount } from 'cypress/vue'

Cypress.Commands.add('mount', (component, options = {}) => {
  // Set up the options object
  options.global = options.global || {}
  options.global.stubs = options.global.stubs || {}
  if (!Array.isArray(options.global.stubs)) {
    options.global.stubs['transition'] = false
  }
  options.global.components = options.global.components || {}
  options.global.plugins = options.global.plugins || []

  // Add any global plugins
  // options.global.plugins.push({
  //   install(app) {
  //     app.use(MyPlugin)
  //   },
  // })

  // Add any global components
  // options.global.components['Button'] = Button

  return mount(component, options)
})
```

cypress/support/component.js

```
import { mount } from 'cypress/svelte'

Cypress.Commands.add('mount', (component, options) => {
  return mount(component, options)
})
```

## Add TypeScript typings for `cy.mount()` commands

When working in [TypeScript](/llm/markdown/app/tooling/typescript-support.md), your custom command needs typings for code completion and to avoid TypeScript errors. Add a `declare global` block that types `cy.mount()` to `cypress/support/component.ts`, which is where Cypress scaffolds the command. To make the typings available to any code in your project, put the block in a `cypress.d.ts` file in the root directory instead. Use this example as a starting point:

*   React
*   Angular
*   Vue
*   Svelte

cypress.d.ts

```
import { mount } from 'cypress/react'

declare global {
  namespace Cypress {
    interface Chainable {
      mount: typeof mount
    }
  }
}
```

cypress.d.ts

```
import { mount } from 'cypress/angular'

declare global {
  namespace Cypress {
    interface Chainable {
      mount: typeof mount
    }
  }
}
```

cypress.d.ts

```
import { mount } from 'cypress/vue'

declare global {
  namespace Cypress {
    interface Chainable {
      mount: typeof mount
    }
  }
}
```

cypress.d.ts

```
import { mount } from 'cypress/svelte'

declare global {
  namespace Cypress {
    interface Chainable {
      mount: typeof mount
    }
  }
}
```

If your specs can't find the types for your custom commands, add `cypress.d.ts` to the `include` array in each `tsconfig.json`:

tsconfig.json

```
{
  "include": ["./src", "cypress.d.ts"]
}
```

## Examples

### Use `cy.mount()` in a component test

Once you register the command, call `cy.mount()` from any component spec with the component and the options your framework's `mount()` accepts. Then query and assert on the rendered component the same way you would on a page, and use what `cy.mount()` [yields](#Yields) when you need the component itself:

*   React
*   Angular
*   Vue
*   Svelte

Stepper.cy.jsx

```
import Stepper from './Stepper'

it('starts the count at the initial value', () => {
  cy.mount(<Stepper initial={5} />)
  cy.get('[data-cy=counter]').should('have.text', '5')
})
```

stepper.component.cy.ts

```
import { StepperComponent } from './stepper.component'

it('sets the count from componentProperties', () => {
  cy.mount(StepperComponent, { componentProperties: { count: 5 } }).then(
    ({ component }) => {
      expect(component.count).to.equal(5)
    }
  )
  cy.get('[data-cy=counter]').should('have.text', '5')
})
```

Stepper.cy.js

```
import Stepper from './Stepper.vue'

it('emits the new count when incremented', () => {
  cy.mount(Stepper, { props: { initial: 5 } }).as('stepper')
  cy.get('[data-cy=increment]').click()

  cy.get('@stepper')
    .its('wrapper')
    .invoke('emitted', 'change')
    .should('deep.equal', [[6]])
})
```

Stepper.cy.js

```
import Stepper from './Stepper.svelte'

it('resets the count through an exported function', () => {
  cy.mount(Stepper, { props: { initial: 5 } }).then(({ component }) => {
    component.reset()
  })
  cy.get('[data-cy=counter]').should('have.text', '0')
})
```

### Remount and rerender components with `cy.mount()`

Calling `cy.mount()` again in the same test unmounts the previous component first, so each mount starts with fresh state. Every framework's `mount()` behaves this way.

In React, use the `rerender()` function that `cy.mount()` yields to update the props of the component that's already mounted. Unlike a second `cy.mount()`, it keeps the component's state:

*   React

Stepper.cy.jsx

```
import Stepper from './Stepper'

it('keeps its count when rerendered with a new label', () => {
  cy.mount(<Stepper label="Count" />).as('stepper')
  cy.get('[data-cy=increment]').click()

  cy.get('@stepper').then(({ rerender }) => {
    rerender(<Stepper label="Total" />)
  })

  cy.get('[data-cy=label]').should('have.text', 'Total')
  cy.get('[data-cy=counter]').should('have.text', '1')
})

it('starts over when mounted again', () => {
  cy.mount(<Stepper />)
  cy.get('[data-cy=increment]').click()

  cy.mount(<Stepper />)
  cy.get('[data-cy=counter]').should('have.text', '0')
})
```

### Load global styles in component tests

Component tests don't run your app's entry file, so the global styles it imports, such as a CSS reset, fonts, or a CSS framework, are missing and components can look unstyled. Import those styles in your component support file so they load for every component test:

cypress/support/component.js

```
// Global styles that your app's entry file imports
import '../../src/styles/global.css'

import { mount } from 'cypress/react'

Cypress.Commands.add('mount', mount)
```

For CSS libraries, component HTML files, and other styling setups, see [Styling components](/llm/markdown/app/component-testing/styling-components.md).

### Add your own options to `cy.mount()`

A custom command can accept options of its own, such as which theme to render a component in. Once it does, `mount: typeof mount` no longer describes the command, so declare its signature yourself. Build it from `Parameters<typeof mount>` and `ReturnType<typeof mount>` to keep the framework's own options and yield. This example wraps the component in JSX, so it goes in `cypress/support/component.tsx`: rename the scaffolded `component.ts`, and Cypress still finds it.

cypress/support/component.tsx

```
import { mount } from 'cypress/react'
import { ThemeProvider } from '../../src/ThemeProvider'

type MountParams = Parameters<typeof mount>
type MountOptions = NonNullable<MountParams[1]> & { theme?: 'light' | 'dark' }

declare global {
  namespace Cypress {
    interface Chainable {
      mount(
        component: MountParams[0],
        options?: MountOptions
      ): ReturnType<typeof mount>
    }
  }
}

Cypress.Commands.add('mount', (component, options = {}) => {
  const { theme = 'light', ...mountOptions } = options

  return mount(
    <ThemeProvider theme={theme}>{component}</ThemeProvider>,
    mountOptions
  )
})
```

Button.cy.tsx

```
import { Button } from './Button'

it('renders in the dark theme', () => {
  cy.mount(<Button>Save</Button>, { theme: 'dark' })
  cy.get('button').should('have.class', 'dark')
})
```

The [React Router](/llm/markdown/app/component-testing/react/examples.md#React-Router), [Redux](/llm/markdown/app/component-testing/react/examples.md#Redux), and [Vue Router](/llm/markdown/app/component-testing/vue/examples.md#Vue-Router) examples follow the same approach.

### Register more than one mount command

When only some components need extra setup, register a second command next to `cy.mount()` instead of adding options to it. `cy.mount()` stays a plain passthrough, and each spec's name for the command says what setup it gets. Like the previous example, this one uses JSX:

cypress/support/component.tsx

```
import { mount } from 'cypress/react'
import { AuthProvider, type User } from '../../src/AuthProvider'

type MountParams = Parameters<typeof mount>

declare global {
  namespace Cypress {
    interface Chainable {
      mount: typeof mount
      mountSignedIn(
        component: MountParams[0],
        user: User,
        options?: MountParams[1]
      ): ReturnType<typeof mount>
    }
  }
}

Cypress.Commands.add('mount', mount)

Cypress.Commands.add('mountSignedIn', (component, user, options) => {
  return mount(<AuthProvider user={user}>{component}</AuthProvider>, options)
})
```

AccountMenu.cy.tsx

```
import { AccountMenu } from './AccountMenu'

it('shows a sign-in link to signed-out visitors', () => {
  cy.mount(<AccountMenu />)
  cy.contains('a', 'Sign in')
})

it('greets a signed-in user by name', () => {
  cy.mountSignedIn(<AccountMenu />, { name: 'Ada' })
  cy.contains('Signed in as Ada')
})
```

## Additional mount command examples

The framework example pages cover more customized mount commands, such as routers, state management, and app-wide providers:

*   [Angular examples](/llm/markdown/app/component-testing/angular/examples.md)
*   [React examples](/llm/markdown/app/component-testing/react/examples.md)
*   [Svelte examples](/llm/markdown/app/component-testing/svelte/examples.md)
*   [Vue examples](/llm/markdown/app/component-testing/vue/examples.md)

## Notes

### `cy.mount()` must be implemented by the user

Calling `cy.mount()` before any file registers it fails with this error:

```
`cy.mount()` must be implemented by the user. There are
full instructions for doing so at the following location.

https://on.cypress.io/mount
```

In the Cypress App, the error appears on the failed test in the Command Log:

Component tests never loaded a file that registers the command. Check that:

*   `Cypress.Commands.add('mount', ...)` is in `cypress/support/component.js` (or `.jsx`, `.ts`, `.tsx`), or in a file that it imports
*   The [`supportFile`](/llm/markdown/app/references/configuration.md#component) option under `component` in your Cypress configuration points at that file and isn't set to `false`

### Property 'mount' does not exist on type 'cy & CyEventEmitter'

TypeScript can't see the typings for your command. Add the `declare global` block from [the typings section](#Add-TypeScript-typings-for-cymount-commands) to your support file or `cypress.d.ts`, and make sure every `tsconfig.json` that covers your specs includes that file.

### A mounting library ends up in your end-to-end tests

The end-to-end and component support files Cypress scaffolds both import `cypress/support/commands.js`, so a `cy.mount()` registered there bundles your framework's mounting library into every end-to-end spec. Move the registration to `cypress/support/component.js`.

## Command Log

Mount a component and assert on its text, as in the React example from [Use `cy.mount()` in a component test](#Use-cymount-in-a-component-test):

Stepper.cy.jsx

```
cy.mount(<Stepper initial={5} />)
cy.get('[data-cy=counter]').should('have.text', '5')
```

The commands above display in the Command Log as:

Whether `cy.mount()` adds a `mount` row depends on your framework's mounting library:

*   Angular always logs the row, with the component's class name, or `Component` when you mount a template string.
*   React and Vue log the row by default. Pass `log: false` in the options to leave it out. In React, `rerender()` adds a `rerender` row the same way.
*   Svelte leaves the row out by default, since Svelte 5 components don't expose a useful name. Pass `log: true` in the options to show it.

## See also

*   [`Cypress.Commands.add()`](/llm/markdown/api/cypress-api/custom-commands.md)
*   [Angular API](/llm/markdown/app/component-testing/angular/api.md) - `cypress/angular` mount options and yields
*   [React API](/llm/markdown/app/component-testing/react/api.md) - `cypress/react` mount options and yields
*   [Svelte API](/llm/markdown/app/component-testing/svelte/api.md) - `cypress/svelte` mount options and yields
*   [Vue API](/llm/markdown/app/component-testing/vue/api.md) - `cypress/vue` mount options and yields
