Skip to content
Latchkey

Cypress Component Testing "cy.mount is not a function"

Cypress component testing does not provide cy.mount automatically - you register it in the component support file using your framework’s adapter. If that registration is missing or wrong, cy.mount is undefined.

What this error means

A component test throws "cy.mount is not a function" (or "mount is not a function"). E2E specs are fine; only component specs fail, because the component support file never added the command.

Cypress output
TypeError: cy.mount is not a function

  > 4 |   cy.mount(<Button label="Save" />);
      |      ^

Common causes

mount command not registered in support

The component support file must import the framework mount and register it as cy.mount. Without that Cypress.Commands.add('mount', mount), the command does not exist.

Wrong framework adapter imported

Importing mount from the React adapter in a Vue project (or vice versa), or from the wrong subpath, leaves cy.mount unregistered or broken.

How to fix it

Register cy.mount in the component support file

cypress/support/component.ts
// cypress/support/component.ts
import { mount } from 'cypress/react';   // or 'cypress/vue'
Cypress.Commands.add('mount', mount);

Point component testing at the support file

cypress.config.ts
// cypress.config.ts
import { defineConfig } from 'cypress';
export default defineConfig({
  component: {
    devServer: { framework: 'react', bundler: 'vite' },
    supportFile: 'cypress/support/component.ts',
  },
});

How to prevent it

  • Register cy.mount in the component support file when scaffolding.
  • Import mount from the adapter that matches your framework.
  • Set component.supportFile so the registration actually loads.

Frequently asked questions

What causes ""cy.mount is not a function""?
The component support file must import the framework mount and register it as cy.mount. Without that Cypress.Commands.add('mount', mount), the command does not exist.
How do I fix "cy.mount is not a function"?
Register cy.mount in the component support file

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card