Cypress: Mixing cy.on()/cy.once() with a one-argument it() function causes test to hang

Created on 14 Sep 2018  路  3Comments  路  Source: cypress-io/cypress

Giving the lambda passed into the it() block a single argument will cause Cypress to pass a function in that must be called for the test to finish.

If you use the cy.on() command inside an it() block with a single-argument function, the test will hang when it reaches cy.on().

HTML:

<html>
  <body>
    <div id='covered' style='position:absolute;background:red;'>asdf</div>
    <div id='uncovered' style='position:absolute;background:blue;'>asdf</div>
  </body>
</html>

Test:

describe('Test', () => {
  it('Tests done()', done => {
    let shouldCallDone = false;

    cy.log('This log should happen.');

    cy.once('fail', (err) => {
      shouldCallDone = true;
    });

    cy.get('#covered').click({ timeout: 1000 });

    cy.log('This log should also happen, but it doesn\'t.');

    cy.get('html').then(() => {
      if (shouldCallDone)
        done();
      else
        throw "done() was never called."
    });
  });

  it('Tests cy.log', () => {
    cy.log('This log should happen too, but it also doesn\'t.');
  });
});

Current behavior:

image

Notice how the test has been running for almost 14 minutes.

Desired behavior:

This code should not cause Cypress to hang.

Versions

Cypress 3.1.0
Windows 10
Electron 59

bug

All 3 comments

I believe this bug is caused by Cypress clearing the timeout erroneously, so the test hangs forever.

Thanks for the bug report!

The code for this is done, but this has yet to be released. We'll update this issue and reference the changelog when it's released.

Released in 3.5.0.

Was this page helpful?
0 / 5 - 0 ratings