Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

cypress

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?

like image 571
Leo Farmer Avatar asked Nov 15 '22 00:11

Leo Farmer


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

like image 105
novice Avatar answered Nov 30 '22 23:11

novice