Skip to content

Commit ed7df85

Browse files
committed
fix: error on XHR stub if response json only contains a number or boolean
Signed-off-by: mrmodise <modisemorebodi@gmail.com>
1 parent 1c2a175 commit ed7df85

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
12

packages/driver/cypress/integration/commands/xhr_spec.js

+30
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,36 @@ describe('src/cy/commands/xhr', () => {
17801780

17811781
cy.contains('#result', '""').should('be.visible')
17821782
})
1783+
1784+
it('works if the JSON file has number content', () => {
1785+
cy
1786+
.server()
1787+
.route({
1788+
method: 'POST',
1789+
url: '/test-xhr',
1790+
response: 'fixture:number.json',
1791+
})
1792+
.visit('/fixtures/xhr-triggered.html')
1793+
.get('#trigger-xhr')
1794+
.click()
1795+
1796+
cy.contains('#result', 12).should('be.visible')
1797+
})
1798+
1799+
it('works if the JSON file has boolean content', () => {
1800+
cy
1801+
.server()
1802+
.route({
1803+
method: 'POST',
1804+
url: '/test-xhr',
1805+
response: 'fixture:boolean.json',
1806+
})
1807+
.visit('/fixtures/xhr-triggered.html')
1808+
.get('#trigger-xhr')
1809+
.click()
1810+
1811+
cy.contains('#result', /true/).should('be.visible')
1812+
})
17831813
})
17841814

17851815
describe('errors', {

packages/server/lib/controllers/xhrs.js

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ module.exports = {
6161
data = ''
6262
}
6363

64+
if (_.isNumber(data) || _.isBoolean(data)) {
65+
data = String(data)
66+
}
67+
6468
const chunk = Buffer.from(data, encoding)
6569

6670
headers['content-length'] = chunk.length

0 commit comments

Comments
 (0)