Skip to content

Commit

Permalink
fix: XHR stub error if response json has number/boolean (#9107)
Browse files Browse the repository at this point in the history
Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
  • Loading branch information
mrmodise and jennifer-shehane committed Nov 9, 2020
1 parent db85c3a commit dae76a8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/driver/cypress/fixtures/boolean.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
1 change: 1 addition & 0 deletions packages/driver/cypress/fixtures/number.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
14
30 changes: 30 additions & 0 deletions packages/driver/cypress/integration/commands/xhr_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,36 @@ describe('src/cy/commands/xhr', () => {

cy.contains('#result', '""').should('be.visible')
})

it('works if the JSON file has number content', () => {
cy
.server()
.route({
method: 'POST',
url: '/test-xhr',
response: 'fixture:number.json',
})
.visit('/fixtures/xhr-triggered.html')
.get('#trigger-xhr')
.click()

cy.contains('#result', 14).should('be.visible')
})

it('works if the JSON file has boolean content', () => {
cy
.server()
.route({
method: 'POST',
url: '/test-xhr',
response: 'fixture:boolean.json',
})
.visit('/fixtures/xhr-triggered.html')
.get('#trigger-xhr')
.click()

cy.contains('#result', /true/).should('be.visible')
})
})

describe('errors', {
Expand Down
4 changes: 4 additions & 0 deletions packages/server/lib/controllers/xhrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ module.exports = {
data = ''
}

if (_.isNumber(data) || _.isBoolean(data)) {
data = String(data)
}

const chunk = Buffer.from(data, encoding)

headers['content-length'] = chunk.length
Expand Down

3 comments on commit dae76a8

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on dae76a8 Nov 9, 2020

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/5.6.0/circle-develop-dae76a8ec0a149d5f4ca4fbe4d15bea1b5f7449d/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on dae76a8 Nov 9, 2020

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/5.5.1/appveyor-develop-dae76a8ec0a149d5f4ca4fbe4d15bea1b5f7449d/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on dae76a8 Nov 9, 2020

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/5.5.1/appveyor-develop-dae76a8ec0a149d5f4ca4fbe4d15bea1b5f7449d/cypress.tgz

Please sign in to comment.