Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress route2 does not work between tests #8686

Closed
Cesaario opened this issue Sep 28, 2020 · 1 comment
Closed

Cypress route2 does not work between tests #8686

Cesaario opened this issue Sep 28, 2020 · 1 comment
Labels
type: duplicate This issue or pull request already exists

Comments

@Cesaario
Copy link

I've read some issues that reported this same bug that I'm experiencing, but in some of them it was said that it is expected, and the routes should indeed be reset between tests. The recent pull request #4176 was supposed to close the issue #1183 , but the issue remains.

Current behavior

Routes are being reset between tests.
Test 1:
image

Test 2:
image

Result:
image

Desired behavior

The route for the endpoint "/todos/1" should not be reset between Test 1 and Test 2

Test code to reproduce

/// <reference types="cypress"/>

describe('Test', () => {
  before(() => {
    cy.visit('https://jsonplaceholder.typicode.com/')
    cy.route2('**/todos/1', 'stub').as('Test');
  })
  it('Test 1', () => {
    cy.get('#run-button').click();

    cy.wait('@Test').then(req => {
      const responseBody = req.response.body;
      expect(responseBody).to.be.equal('stub');
    })
  })
  it('Test 2', () => {
    cy.get('#run-button').click();
    
    cy.wait('@Test').then(req => {
      const responseBody = req.response.body;
      expect(responseBody).to.be.equal('stub');
    })
  })
})

Versions

Windows 10
Chrome 85
Cypress 5.2.0*

*Cypress 5.2.0 has a bug that we can't match routes with external url's. So I used the branch from PR #8662

@jennifer-shehane
Copy link
Member

The closing of #1183 allows you to not have to redefine cy.server() in between tests, so it will only need to be defined once.

That fix has no effect on the defined aliases. Defined aliases (like your @test) will still be reset between each test and cannot be defined in a before hook. Duplicate of #665

@jennifer-shehane jennifer-shehane added the type: duplicate This issue or pull request already exists label Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants