Fix "Cannot read property '__error' of null" error (#7534)

This commit is contained in:
Chris Breiding
2020-06-01 04:38:19 -04:00
committed by GitHub
parent be6dccb7bb
commit 7a8b58fa2f
2 changed files with 46 additions and 3 deletions
@@ -93,10 +93,9 @@ class XMLHttpRequest {
}
_getFixtureError () {
const body = this.response && this.response.body
const err = body.__error
const err = this.response?.body?.__error
if (body && err) {
if (err) {
return err
}
}
@@ -0,0 +1,44 @@
import $XHR from '../../../../src/cypress/xml_http_request'
describe('src/cypress/xml_http_request', () => {
let xhr
let $xhr
beforeEach(() => {
xhr = {
id: '1',
url: 'http://example.com',
method: 'GET',
}
$xhr = $XHR.create(xhr)
})
context('._getFixtureError', () => {
it('returns __error property on response body', () => {
$xhr.response = {
body: {
__error: 'Something went wrong',
},
}
const err = $xhr._getFixtureError()
expect(err).to.equal('Something went wrong')
})
it('returns undefined if response does not exist', () => {
const err = $xhr._getFixtureError()
expect(err).to.be.undefined
})
it('returns undefined if response body does not exist', () => {
$xhr.response = {}
const err = $xhr._getFixtureError()
expect(err).to.be.undefined
})
})
})