cypress: Problem cancelling XHRs from previous test

Current behavior:

Yep, there is an issue if you don’t wait for all XHRs to finish after a test. When it tries to cancel the XHR it fails with the error: -

UnsubscriptionError: 1 errors occurred during unsubscription:
  1) TypeError: Cannot set property 'aborted' of undefined

if I do an explicit cy.wait(2000) or cy.wait('@myxhr') it works note it’s the following test that fails, not the one with the XHR

Desired behavior:

The XHR should be cancelled correctly before the next test starts

How to reproduce:

Have a longish running XHR fire at the end of one test and have a subsequent test.

Additional Info (images, stack traces, etc)

It seems to happen when I am faking a route failure (status 500) and then make another (non-faked) XHR (to report the error to a server). e.g.: -

cy.route({
  method: 'PUT',
  url: '/Endpoint/Id',
  status: 500,
  response: ''
}).as('saveStuff');
  • Operating System: Ubuntu 16.04
  • Cypress Version: 1.0.2
  • Browser Version: Electron 53

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 9
  • Comments: 62 (11 by maintainers)

Commits related to this issue

Most upvoted comments

@brian-mann I still have the problem in 1.0.3 (Chrome 62, Electron 53 in both)

cypress_runner.js:136633 TypeError: Cannot set property 'aborted' of undefined
    at XMLHttpRequest.XHR.abort (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:65539:23)
    at XMLHttpRequest.onReadyStateFn (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:65617:27)
From previous event:
    at run (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:61887:15)
    at Object.cy.(anonymous function) [as visit] (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:62107:11)
    at Context.runnable.fn (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:62238:20)
    at callFn (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:32092:21)
    at Test.Runnable.run (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:32085:7)
    at https://spb.tele2.ru/__cypress/runner/cypress_runner.js:65090:28
From previous event:
    at Object.onRunnableRun (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:65089:20)
    at $Cypress.action (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:60592:51)
    at Test.Runnable.run (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:64240:20)
    at Runner.runTest (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:32555:10)
    at https://spb.tele2.ru/__cypress/runner/cypress_runner.js:32661:12
    at next (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:32475:14)
    at https://spb.tele2.ru/__cypress/runner/cypress_runner.js:32485:7
    at next (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:32417:14)
    at https://spb.tele2.ru/__cypress/runner/cypress_runner.js:32453:5
    at timeslice (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:27694:27)
logError @ cypress_runner.js:136633

Just to confirm, we’re not using this.retries() in our tests and still seeing this, but that’s worth checking for others.

I’m facing the same problem with cypress 1.4.1.

Released in 3.1.4.

@jennifer-shehane How is the status of this, now having a reproducible example?

@bahmutov @jennifer-shehane … I created a simple public reproduction demo:

Tested page: https://mlc-demo-cypress.firebaseapp.com (Stackblitz source: https://stackblitz.com/edit/mlc-angular-demo-cypress) Testing code:

describe('simple reproduction of a problem with cancelling XHRs', () => {

	before(() => {
		cy.visit('https://mlc-demo-cypress.firebaseapp.com');
		cy.wait(2000);
	});

	it('getting the album button and clicking it', () => {
		cy.get('[data-cy=getAlbums]').should('have.length', 1).click();
	});

	it('getting the todos button and clicking it', () => {
		cy.get('[data-cy=getTodos]').should('have.length', 1).click();
	});

	it('getting the user button and clicking it', () => {
		cy.get('[data-cy=getUsers]').should('have.length', 1).click();
	});
});

The result of the test looks: image And the error like: image

We’re facing the same problem with 3.1.0.

Sadly @StormPooper’s hack doesn’t seem to work for us.

We’re doing this (based on https://github.com/cypress-io/cypress/issues/761#issuecomment-352375786) in our support/index.js:

Cypress.on('uncaught:exception', hackToNotFailOnCancelledXHR);
Cypress.on('fail', hackToNotFailOnCancelledXHR);

function hackToNotFailOnCancelledXHR(err) {
	const realError =
		err.message.indexOf("Cannot set property 'aborted' of undefined") ===
		-1;
	if (realError) throw err;
	else console.error(err); // eslint-disable-line no-console
}

Had to catch it in fail too since it doesn’t seem to treat it as an uncaught exception from your own tests. It’s still not great as it means if something fails for the same reason it’ll assume everything’s fine, but we’ve found it better than loading another page after each test.

I’m getting these errors when calling visit on a new url after running over from one test spec file to the next.

Currently having to do something nasty like:

Cypress.on('uncaught:exception', (err, runnable) => {
    return err.message.indexOf('Cannot set property \'aborted\' of undefined') === -1
});

@StormPooper - thanks for that suggestion. Unfortunately, commenting out either doesn’t work. Only using it on uncaught:exception results in the original cannot set 'aborted' failure, and only using it on fail results in all subsequent tests immediately passing and never running.

Hopefully Cypress is able to handle this scenario properly soon. It’s pretty much the only thing standing in the way of migrating from TestCafe to Cypress.

Still an issue with 3.0.1 too.

@rafaelchiti did you have any success with the PubNub long polling and Cypress? Some of the functionality i want to test is dependent on it so I don’t really want to stub it out.

@brian-mann If you no longer abort XHRs between tests how come we all still get this error ? I’m using 2.1.0 and I keep having this problem. Thanks

Hi, I’m using rxjs and redux-obsevables in my app. There was no problem in Cypress 3.1.2 with aborting requests by takeUntil operator from rxjs. But after upgrade to 3.1.4 I sometimes have an error like:

Error: Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'json').

I think it’s caused by solving this 🐛

@jennifer-shehane We are able to reproduce against a website. We do not want to publicly share the website URL — if you are interested, we can send the website URL via mail and post the tests here a dot menk at imi dot de is mail mail

I am also experiencing this with 1.4.2. I am not making any requests or even repeating cy.visit at the beginning of each test. I also don’t see any aborted XHRs in the Cypress sidebar or failed requests in the Chome Dev Tools.