mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-03 13:30:26 -05:00
Fix "Cannot read property '__error' of null" error (#7534)
This commit is contained in:
@@ -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
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user