Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

event is undefined in XHR onload handlers using cypress open #2859

Closed
meastes opened this Issue Nov 29, 2018 · 3 comments

Comments

3 participants
@meastes
Copy link

meastes commented Nov 29, 2018

Current behavior:

Currently, Cypress will fail if the page uses an onload event handler and relies on data from the event. It appears that the event is undefined when the onload handler is executed. This issue only appears in Cypress 3.1.1 and 3.1.2; it is not present in Cypress 3.1.0 and earlier. Here is the code that fails for me:

var request = new XMLHttpRequest();
request.open('GET', 'http://127.0.0.1:8088/', true);
request.onload = function (evt) {
  if (evt.target.status >= 200 && evt.target.status < 400) { // This will fail since evt will be undefined
    console.log('success!');
  }
}
request.send();

It also appears that the test will execute fine with cypress run. Only cypress open has the issue.

Desired behavior:

Cypress should execute onload event handlers with the correct onload event.

Steps to reproduce:

An example of the issue is available at https://github.com/meastes/cypress-test-tiny

  1. Clone https://github.com/meastes/cypress-test-tiny
  2. Run npm install
  3. Run npm start to start the web server
  4. Run npm run cypress:open
  5. Execute the spec.js test
  6. Notice that it will fail because the event in the XHR request is undefined

Versions

Cypress 3.1.2, MacOS 10.13.6, Chrome 70

@jennifer-shehane

This comment has been minimized.

Copy link
Member

jennifer-shehane commented Nov 30, 2018

Thanks so much for providing a repo to reproduce the issue. I can indeed reproduce this running the code provided.

Test code:

it('works', () => {
  cy.visit('http://127.0.0.1:8088');
})

Command Log on very 1st run:

screen shot 2018-11-30 at 11 02 04 am

Command Log on every run after 1st:

screen shot 2018-11-30 at 10 57 29 am

@lilaconlee

This comment has been minimized.

Copy link
Contributor

lilaconlee commented Dec 13, 2018

This was fixed with #2924 and will be part of the next release.

@jennifer-shehane

This comment has been minimized.

Copy link
Member

jennifer-shehane commented Mar 13, 2019

This was released in 3.1.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.