i want to reset config like when we refresh the browser every time cypress test runs. i am using
"content-type": "application/x-protobuf"
as default header but when one of my responses is json cypress change it to application/json by default.
this is my interceptor:
Cypress.Commands.overwrite('intercept', (originalFn, { method, url }, options) => {
method = 'POST'
url = `${Cypress.env('EXTERNAL_API')}/${url}`
options = {
...options,
headers: Cypress.env('DEFAULT_HEADER'),
}
return originalFn(method, url, options)
})
I have the problem. when i pass body
instead of fixture
in the interceptor , cypress forces the header to application/json
. no way to change it.
to solve the problem i passed my json
file as a fixture
and set my custom header according to that.
Cypress.Commands.overwrite('intercept', (originalFn, { method, url }, options) => {
method = 'POST'
url = `${Cypress.env('EXTERNAL_API')}/${url}`
const isJsonHeader = options?.fixture?.toLowerCase()?.includes('.json') ? true : false
options = {
...options,
headers: isJsonHeader ? Cypress.env('JSON_HEADER') : Cypress.env('DEFAULT_HEADER'),
}
return originalFn(method, url, options)
})