Skip to content

Using cy.server() and cy.route() not working in before hooks #595

@pawelgalazka

Description

@pawelgalazka

Current behavior:

I'm getting error in Cypress app console: CypressError: cy.route() cannot be invoked before starting the cy.server() when I use cy.server() in top before hook and then cy.route() in children contexts before hooks.

If I remove top cy.server() and move it to before hook before each cy.route() call then I get fail for second describe context with error: CypressError: The XHR server is unavailable or missing. This should never happen and likely is a bug. Open an issue if you see this message.

Desired behavior:

I should be able to use cy.route() and cy.server() within before hooks.

Test code:

describe('test', () => {
  before(() => {
    cy.server()
  })

  describe('case with http 500', () => {
    before(() => {
      // cy.server()
      cy.route({
        method: 'GET',
        url: '/api?*',
        status: 500,
        response: {}
      })
      cy.visit('http://app.dev/')
    })

    it('test n1', () => {

    })

    it('test nr 2', () => {

    })
  })

  describe('case with http 408', () => {
    before(() => {
      // cy.server()
      cy.route({
        method: 'GET',
        url: '/api?*',
        status: 408,
        response: {}
      })
      cy.visit('http://app.dev')
    })

    it('test nr 3', () => {

    })

    it('test nr 4', () => {

    })
  })
})
  • Cypress Version: 0.19.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions