Search code examples
angularcypresscache-control

How to disable caching for intercepted calls?


I am currently using Cypress 6.4.0 which starts my Angular app. This Angular app calls a time synchronization route of the backend at the start. We intercept this call via:

cy.wait('/api/t', { requestTimeout: 10_000 }).then((req) => {
    expect(req.response!.statusCode).to.equal(200);
    // some extra stuff...
});

This works for the first test, but the seconds always fails. I checked the network log and it seems when that the second response comes from the browser cache. I first thought that the backend or Angular's cache removed the pragma and no-cache headers, but when running the app without Cypress the headers are there.

My test has 2 tests in it and the second one fails. Or, if I have 1 test in it and reload it inside the Cypress browser using R.

So, is there a way to disable the caching in Cypress?


Solution

  • Check the post about intercept problems on Gleb Bahmutov blog

    cy.intercept('/todos', req => {
      delete req.headers['if-none-match']
    })