Skip to content
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

Modify headers and status code but not stubbing response #190

Closed
fvanwijk opened this issue Jul 15, 2016 · 12 comments · Fixed by #4176
Closed

Modify headers and status code but not stubbing response #190

fvanwijk opened this issue Jul 15, 2016 · 12 comments · Fixed by #4176
Assignees
Labels
topic: network type: feature New feature that does not currently exist

Comments

@fvanwijk
Copy link
Contributor

fvanwijk commented Jul 15, 2016

I have an XHR request that responds normally with a status 200 and some data.
There is one case where the response is enriched with some header data. I want to simulate this case.

This is the mock setup:

cy.server().route({
  method: 'POST',
  url: /some-url/,
  headers: { key: 'value' }
});

The resulting call is a non stubbed call but also the key: value headers are missing. They are not missing when I add a stubbed response to the route config.
The same happens with status.

@jennifer-shehane jennifer-shehane added the type: feature New feature that does not currently exist label Jul 15, 2016
@andrewleith
Copy link

Any progress on this stale issue? Should this at least be removed from the docs if it isnt a feature?

@MarcoNicolodi
Copy link

I was trying to stub a 500 status code without stubbing the response itself and it wasnt working. The XHR kept returning a 200 response.

Passing an empty array as response solved it.

@jennifer-shehane jennifer-shehane added the stage: proposal 💡 No work has been done of this issue label Apr 23, 2018
@jennifer-shehane
Copy link
Member

I feel that the docs are rather clear on the point that the response determines a routes stubbing or not.

If you do not pass a response to a route, Cypress will pass the request through without stubbing it. We can still wait for the request to resolve later.
-- https://docs.cypress.io/api/commands/route.html#Without-Stubbing

If you pass a response to cy.route(), Cypress will stub the response in the request.
-- https://docs.cypress.io/api/commands/route.html#With-Stubbing

But, we are always looking for ways to improve our docs if there are some areas that were confusing you could point out.

@andrewleith
Copy link

Like @fvanwijk, I am trying to get cypress to add some headers to certain XHR requests. If his example isn't how you do it, then how do you do it?

@jennifer-shehane
Copy link
Member

You can't currently stub any options of a request unless you also stub the response. This is a feature that would have to be added to Cypress.

@andrewleith
Copy link

Oh, well maybe its worth explicitly putting that note in the docs? I seemed to think it was supported back when i was trying this 😀

@MarcoNicolodi
Copy link

MarcoNicolodi commented Apr 23, 2018

I dont think its explicit enough as well :)

@loicplaire
Copy link

I would agree that it would be a very useful feature. For example on our project we rely on the Cloudfront cloudfront-viewer-country header to geolocate our users so I would like to add that header when mocking the page request without modifying anything else in the response.
Without it, I can't think of any other way to test our geolocation feature.

@AshwinHexad
Copy link

Any update on this feature?

@cypress-bot cypress-bot bot added stage: ready for work The issue is reproducible and in scope and removed stage: proposal 💡 No work has been done of this issue labels Mar 26, 2019
@jennifer-shehane
Copy link
Member

This is part of the work planned within #4176 which is currently in progress.

@cypress-bot cypress-bot bot added stage: work in progress and removed stage: ready for work The issue is reproducible and in scope labels Jun 10, 2020
@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: work in progress labels Jun 24, 2020
@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review and removed stage: needs review The PR code is done & tested, needs review stage: work in progress labels Aug 25, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 1, 2020

Released in 5.1.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.1.0, please open a new issue.

@cypress-bot cypress-bot bot removed the stage: needs review The PR code is done & tested, needs review label Sep 1, 2020
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Sep 1, 2020
@jennifer-shehane
Copy link
Member

The features requested in this issue are now possible as part of cy.route2().

cy.route2() is currently experimental and requires being enabled by passing "experimentalNetworkStubbing": true through your Cypress configuration. This will eventually be merged in as part of our standard API.

Please see the cy.route2() docs for full details: https://on.cypress.io/route2

If you encounter any issues or unexpected behavior while using cy.route2() we encourage you to open a new issue so that we can work out all the issues before public release. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: network type: feature New feature that does not currently exist
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants