Cannot read property '__error' of null
csalazar1 opened this issue · comments
As of version 4.6.0, Cypress has been throwing this exception during a very simple test that consists of
- Routing a request
- Logging in
- Visiting a page
- Make sure an element is displayed
This issue is reproducible with 4.7.0 version as well. It works perfectly fine in version 4.5.0.
Here's how to reproduce
- Set baseUrl in cypress.json to: https://qa1-cypress.st.dev
- Run the following test using either Cypress version 4.6.0 or later
it('Business Unit Test', () => {
cy.server()
cy.route({
method: 'GET',
url: '/Settings/GetBusinessUnits*',
response: [{
Id: 56345,
Name: 'Test BU',
OfficialName: 'Test BU',
Active: true,
Logo: null,
PostDate: null,
QbExportState: null
}],
status: 200
})
cy.request('POST', '/Auth/Login', { username: 'cydemoadmin', password: 'Test1@#$%' })
cy.visit('/#/Settings/business-units')
cy.get('.e2e-column-name').contains('Test BU').should('be.visible')
})
Same, tests that never had this now have it appearing all over the place. Cypress says it originates from our app but it doesnt seem like it is, or if it is its not appearing in a console anywhere.
Struggled with this as well and the issue seems to with 200
responses with response bodies of the literal value null
. Cypress errors handling them and the request in the runner appears to be hung. This does break my tests.
I'll put up a repro in the next hour but for now, the following should be a good workaround:
it('my test', () => {
cy.on('uncaught:exception', err => {
return !err.message.includes(`Cannot read property '__error' of null`);
});
// my test code ...
});
EDIT: I ruled out the simplest case when I was attempting to repro this. The demo project is here: https://github.com/FLGMwt/cypress-null-response-regression
I'm not yet sure what's different about my application code that returns null and this demo server that returns null, but I do hope this is a start. I'll give a little time to repro-ing tomorrow, but hope this helps
Thanks for providing a reproducible example! I can recreate this and see this was introduced in Cypress 4.6.0. I suspect this is related to our error improvements #3930
I also see these files were converted from coffeescript in the 4.6.0 release in #7227
spec.js
it('Business Unit Test', () => {
cy.request('POST', 'https://qa1-cypress.st.dev/Auth/Login', { username: 'cydemoadmin', password: 'Test1@#$%' })
cy.visit('https://qa1-cypress.st.dev/#/Settings/business-units')
cy.get('.foobar')
})
4.5.0
4.6.0
Stack trace
This is throwing from this line of code, where the body
is null
.
In the example, there is a request to https://qa1-cypress.st.dev/DataProvider/GetEmbeddedPhoneUserConfiguration
that has a null
response.body.
TypeError: The following error originated from your application code, not from Cypress.
> Cannot read property '__error' of null
When Cypress detects uncaught errors originating from your application it will automatically fail the current test.
This behavior is configurable, and you can choose to turn this off by listening to the `uncaught:exception` event.
at XMLHttpRequest._getFixtureError (https://qa1-cypress.st.dev/__cypress/runner/cypress_runner.js:163144:22)
at onLoadFn (https://qa1-cypress.st.dev/__cypress/runner/cypress_runner.js:161996:27)
at XMLHttpRequest.<anonymous> (https://qa1-cypress.st.dev/__cypress/runner/cypress_runner.js:161980:25)
From previous event:
at run (https://qa1-cypress.st.dev/__cypress/runner/cypress_runner.js:155845:19)
at Object.cy.<computed> [as request] (https://qa1-cypress.st.dev/__cypress/runner/cypress_runner.js:156289:11)
at Context.runnable.fn (https://qa1-cypress.st.dev/__cypress/runner/cypress_runner.js:156514:21)
at callFn (https://qa1-cypress.st.dev/__cypress/runner/cypress_runner.js:95404:21)
at Test.../driver/node_modules/mocha/lib/runnable.js.Runnable.run (https://qa1-cypress.st.dev/__cypress/runner/cypress_runner.js:95391:7)
at https://qa1-cypress.st.dev/__cypress/runner/cypress_runner.js:160893:28
From previous event:
at Object.onRunnableRun (https://qa1-cypress.st.dev/__cypress/runner/cypress_runner.js:160881:20)
at $Cypress.action (https://qa1-cypress.st.dev/__cypress/runner/cypress_runner.js:152580:61)
at Test.Runnable.run (https://qa1-cypress.st.dev/__cypress/runner/cypress_runner.js:159483:13)
at Runner.../driver/node_modules/mocha/lib/runner.js.Runner.runTest (https://qa1-cypress.st.dev/__cypress/runner/cypress_runner.js:96063:10)
at https://qa1-cypress.st.dev/__cypress/runner/cypress_runner.js:96189:12
at next (https://qa1-cypress.st.dev/__cypress/runner/cypress_runner.js:95972:14)
at https://qa1-cypress.st.dev/__cypress/runner/cypress_runner.js:95982:7
at next (https://qa1-cypress.st.dev/__cypress/runner/cypress_runner.js:95884:14)
at https://qa1-cypress.st.dev/__cypress/runner/cypress_runner.js:95950:5
at timeslice (https://qa1-cypress.st.dev/__cypress/runner/cypress_runner.js:89876:27)
The code for this is done in cypress-io/cypress#7534, but has yet to be released.
We'll update this issue and reference the changelog when it's released.
@jennifer-shehane is this going to be released as a hotfix (in a day or two) ? or will it be released according to the normal release schedule (every two weeks if i remember correctly) ?
This will be released in our normal release schedule next Monday. You can downgrade to Cypress 4.5.0 in the meantime so it's not blocking.
Released in 4.8.0
.
This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v4.8.0, please open a new issue.