How to set headers on every request in Cypress using cy.intercept

Viewed 4042

I am trying to add a request header to every api request generated in Cypress. I have a version that works using cy.server but this is being depricated, so I am trying to replace it with cy.intercept. I don't see any errors when I run this code, but I don't see the header added to my requests either:

beforeEach(() => {
  
  cy.intercept('*',(req) => {
    console.log('MATCHED INTERCEPT')
    req.headers['my-test'] = 'TEST'
  })
})

I can see the log text 'MATCHED INTERCEPT' in the console, so I know that the intercept is matching something....

Can anyone tell me what is wrong with this code?

1 Answers

I think you will not be able to see the new header after intercepting, as per their documentation :

enter image description here

Hope this was useful

Related