Cypress - Add custom header for all XHR requests
Now cy.server
is deprecated, you can use cy.intercept
instead:
cy.intercept('http://api.company.com/', (req) => {
req.headers['authorization'] = `token ${token}`
})
More info in the docs.
Just to make everyone aware, I communicated with makers of Cypress
and got to know that the stubbing of outgoing request is under development and can be tracked under - https://github.com/cypress-io/cypress/issues/687