Stubbing requests via cy.intercept doesnt work the same way as cy.route
See original GitHub issueCurrent behavior
The request I want to stub looks like so with the old cy.route
cy.route({
method: 'POST',
url: '**/sessions',
status: 200,
response: {
success: true,
},
headers: {
'x-token': "token",
},
})
With this, I get the “x-token” returned as a header back to the client. alongside other headers.
connection: "keep-alive"
content-length: "16"
content-type: "application/json; charset=utf-8"
date: "Thu, 11 Feb 2021 12:58:34 GMT"
vary: "Accept-Encoding",
x-token: "token"
Trying out the new cy.intercept API,
cy.intercept('**/sessions', {
body: { success: true },
headers: {
x-token: "token"
},
})
This is what I get back
content-type: "application/json"
Desired behavior
I expect the x-token to be part of the headers returned in the response. If Im missing anything, please let me know, thanks
Test code to reproduce
https://github.com/Tevinthuku/cypress-test-tiny https://codesandbox.io/s/modest-hofstadter-gl5xj?file=/src/App.js
Versions
Cypress v 6.4.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (2 by maintainers)
Top Results From Across the Web
intercept - Cypress Documentation
Spy and stub network requests and responses. Tip: We recommend you read the Network Requests guide first. All intercepts are automatically cleared before....
Read more >Cypress cy.intercept Problems - Gleb Bahmutov
The command cy.intercept can match requests using a substring, a minimatch, or a regular expression. By default, it intercepts requests matching ...
Read more >cy.intercept() not stubbing API in Cypress - Stack Overflow
Supply a response body to stub in the matching route. In cy.intercept(method, url, routeHandler?) , routeHandler is a more complicated beast.
Read more >cy.request vs. cy.intercept - DEV Community
cy.intercept does not make a request, but rather "listens" to requests that occur on the network layer. If we "ask" Cypress to name ......
Read more >A Practical Guide to Intercepting Network Requests in Cypress
With minimatch, we don't care what the final ID number is, ... With .intercept() it is possible to work with fetch requests the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sainthkh of the 3 options you’ve listed, I think it would make sense to modify (1) slightly and go with it:
If we only apply it to stubbed requests, like we do with the other CORS headers, it should help avoid unnecessary modification of the header.
Another issue was opened about this same confusion, so it’s probably worth fixing: https://github.com/cypress-io/cypress/issues/14654
Released in
7.3.0
.This comment thread has been locked. If you are still experiencing this issue after upgrading to Cypress v7.3.0, please open a new issue.