Skip to content

Stubbing requests via cy.intercept doesnt work the same way as cy.route #15050

@Tevinthuku

Description

@Tevinthuku

Current 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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions