-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stubbing requests via cy.intercept doesnt work the same way as cy.route #15050
Comments
Based on this reproduction with |
I am experiencing the same issue. This code should add a header to every request, but I don't see any header added to my requests:
|
It's a CORS problem. The problematic code's domain is We can currently bypass this problem by adding it('works', () => {
cy.visit('https://csb-gl5xj-g6j2kdska.vercel.app/')
cy.intercept('**/sessions', {
body: { success: true },
headers: {
'Access-Control-Expose-Headers': 'x-token', // <= ADD THIS LINE
'x-token': 'token',
},
}).as('loginRequest')
cy.get('[data-testid=username-input]').type('user')
cy.get('[data-testid=password-input]').type('userpassword')
cy.get('[data-testid=signin-button]').click()
cy.wait('@loginRequest').then((res) => {
let headers = res.response.headers
expect(headers).to.have.property('x-token')
})
}) @flotwig I think there can be several solutions for this problem:
What do you think is the best solution? Maybe there can be other better ones. |
@jennifer-shehane I checked the PR and the change is related with the CORS origin, not the exposed header properties. The PR doesn't do anything with |
@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: #14654 |
The code for this is done in cypress-io/cypress#16415, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior
The request I want to stub looks like so with the old cy.route
With this, I get the "x-token" returned as a header back to the client. alongside other headers.
Trying out the new cy.intercept API,
This is what I get back
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
The text was updated successfully, but these errors were encountered: