Cypress wait() for intercept() is not triggered for NEW URL only

Viewed 47

Initiating a visit(), it triggers three fetches before ending up on the final NEW URL. Each fetches triggers their corresponding wait() - except the NEW URL.

describe('login', () => {
  it('login', () => {
    cy.intercept('/_next/static/development/_devMiddlewareManifest.json').as('fetch1')
    cy.intercept('http://localhost:3333/auth/works/token-check').as('fetch2')
    cy.intercept('/_next/static/development/_devPagesManifest.json').as('fetch3')
    cy.intercept('http://localhost:3002/login').as('login')

    cy.visit('/')

    // cy.wait(['@fetch1', '@fetch2', '@fetch3', '@login'])
    cy.wait('@fetch1')
    cy.wait('@fetch2')
    cy.wait('@fetch3')
    // cy.wait('@login')
    cy.wait('@login', {
      requestTimeout: 10000
    })

    cy.url().should('include', '/login')
  })
})

enter image description here

1 Answers

The (new page) log entry is not actually a network request, it just informs you that the page has navigated to a new URL.

Since your app is a SPA, this is most likely caused by the app router and not by any traffic coming over the network, so you can't use cy.intercept() to catch it.

You last command cy.url().should('include', '/login') should be sufficient to wait for the new page to occur.

Related