Skip to content

Commit

Permalink
chore: Bind this correctly when setting response headers with cy.rout…
Browse files Browse the repository at this point in the history
…e() (#18859)
  • Loading branch information
chrisbreiding authored Nov 9, 2021
1 parent 925fc65 commit e66734d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
27 changes: 27 additions & 0 deletions packages/driver/cypress/integration/commands/xhr_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,33 @@ describe('src/cy/commands/xhr', () => {
})
})

// https://github.com/cypress-io/cypress/issues/18858
it('can stub headers', (done) => {
cy
.route({
url: '/foo',
response: '',
headers: {
'some-header': 'header-value',
},
}).as('getFoo')
.window().then((win) => {
win.$.ajax({
url: '/foo',
error (_a, _b, err) {
done(`Errored but should not have: ${err.stack}`)
},
})

return null
})
.wait('@getFoo')
.then((xhr) => {
expect(xhr.response.headers['some-header']).to.equal('header-value')
done()
})
})

// https://github.com/cypress-io/cypress/issues/2372
it('warns if a percent-encoded URL is used', () => {
cy.spy(Cypress.utils, 'warning')
Expand Down
3 changes: 1 addition & 2 deletions packages/driver/src/cypress/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ export class Server {
this.setHeader(xhr, 'response', route.response, responser)
this.setHeader(xhr, 'matched', `${route.url}`)
this.setHeader(xhr, 'delay', route.delay)

return this.setHeader(xhr, 'headers', route.headers, this.transformHeaders)
this.setHeader(xhr, 'headers', route.headers, this.transformHeaders.bind(this))
}

route (attrs = {}) {
Expand Down

4 comments on commit e66734d

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e66734d Nov 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/8.7.1/circle-develop-e66734d514e12655accab1dd6d047958583ea3d1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e66734d Nov 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/8.7.1/appveyor-develop-e66734d514e12655accab1dd6d047958583ea3d1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e66734d Nov 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/8.7.1/appveyor-develop-e66734d514e12655accab1dd6d047958583ea3d1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e66734d Nov 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/8.7.1/circle-develop-e66734d514e12655accab1dd6d047958583ea3d1/cypress.tgz

Please sign in to comment.