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.
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
import { mount } from 'cypress/react'; // or 'cypress/vue'
Cypress.Commands.add('mount', mount);Point component testing at the support file
// 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.mountin the component support file when scaffolding. - Import
mountfrom the adapter that matches your framework. - Set
component.supportFileso the registration actually loads.