Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
100
rated 0 times [  105] [ 5]  / answers: 1 / hits: 11452  / 5 Years ago, fri, march 1, 2019, 12:00:00

I notice that X-CSRFToken header is getting removed between tests, for all the XHR requests that triggered from application under test. I'm not sure to preserve this header, as I'm already preserving the Cookies through Cypress.Cookies.preserveOnce('sessionid', 'csrftoken')



Hence, I thought of appending the custom header X-CSRFToken to all the XHR requests from the application. Here is the script I used, where I'm fetching the csrftoken from cookies and setting to custom header.



cy.server({
onAnyRequest: function(route, proxy) {
proxy.xhr.setRequestHeader('X-CSRFToken', cy.getCookie('csrftoken'));
}
})


Here, I'm getting the below error,



Argument of type '{ onAnyRequest: (route: any, proxy: any) => void; }' is not assignable to parameter of type 'Partial<ServerOptions>'.
Object literal may only specify known properties, and 'onAnyRequest' does not exist in type 'Partial<ServerOptions>'.


I'm expecting any working solution to this approach or a better solution.


More From » typescript

 Answers
27

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


[#8674] Wednesday, February 27, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kourtney

Total Points: 368
Total Questions: 103
Total Answers: 85

Location: Bonaire
Member since Sat, May 1, 2021
3 Years ago
kourtney questions
;