cypress-io/cypress · error · Error
cy.origin from a component spec is not allowed
Error message
cy.origin from a component spec is not allowed
What it means
Thrown by @cypress/mount-utils setupHooks, which overwrites the `origin` command during component testing. cy.origin executes callbacks in a cross-origin frame reached via cy.visit; CT never visits a page and operates on a single mounted frame, so cross-origin execution has no valid target. The overwrite throws whenever the command is called.
Source
Thrown at npm/mount-utils/src/index.ts:46
}
// When running component specs, we cannot allow "cy.visit"
// because it will wipe out our preparation work, and does not make much sense
// thus we overwrite "cy.visit" to throw an error
Cypress.Commands.overwrite('visit', () => {
throw new Error(
'cy.visit from a component spec is not allowed',
)
})
Cypress.Commands.overwrite('session', () => {
throw new Error(
'cy.session from a component spec is not allowed',
)
})
Cypress.Commands.overwrite('origin', () => {
throw new Error(
'cy.origin from a component spec is not allowed',
)
})
// @ts-ignore
Cypress.on('test:before:after:run:async', () => {
optionalCallback?.()
})
}
View on GitHub (pinned to 0d85fdc912)
Solutions
- Remove cy.origin from component specs; CT cannot drive cross-origin frames.
- For third-party iframe content, stub the iframe or the network calls (cy.intercept) instead of driving the remote origin.
- Move genuine cross-origin test flows to an e2e spec.
- Split shared support so cross-origin helpers are only imported by e2e specs.
Example fix
// before (component spec)
cy.origin('auth.example.com', () => { cy.get('#user').type('sam') })
// after — stub the auth call instead
cy.intercept('POST', '/auth/login', { fixture: 'user.json' }).as('login')
cy.mount(<App/>) Defensive patterns
Strategy: type-guard
Validate before calling
if (Cypress.testingType === 'e2e') {
cy.origin(url, fn)
} Type guard
const isE2E = (): boolean => Cypress.testingType === 'e2e'
Prevention
- Keep cross-origin flows in e2e specs only.
- Stub third-party iframes/network in CT via cy.intercept.
- Lint against cy.origin in component spec files.
When it happens
Trigger: Calling `cy.origin(url, fn)` inside a component spec. Triggered for any CT run once setupHooks has installed the overwrites.
Common situations: Reusing an e2e cross-origin login flow inside a CT spec; testing a component that embeds a third-party iframe and attempting to drive the iframe via cy.origin; a shared support helper that abstracts cross-origin steps.
Related errors
- cy.visit from a component spec is not allowed
- cy.session from a component spec is not allowed
- [@cypress/react] 🔥 Hmm, cannot find root element to mount t
- Could not find a project with projectType "application" in "
- Your Cypress devServer config is missing a required webpackC
AI-assisted analysis of cypress-io/cypress@0d85fdc912 (2026-08-12).
Data as JSON: /api/errors/f8c35dd9245876bc.
Report an issue: GitHub.