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

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

Closed
SecondFlight opened this issue Sep 14, 2018 · 3 comments · Fixed by #5097
Closed

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

SecondFlight opened this issue Sep 14, 2018 · 3 comments · Fixed by #5097

Comments

@SecondFlight
Copy link

SecondFlight commented Sep 14, 2018

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

@kuceb
Copy link
Contributor

kuceb commented Jan 28, 2019

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

Thanks for the bug report!

@kuceb kuceb added stage: needs investigating Someone from Cypress needs to look at this type: bug labels Jan 28, 2019
@kuceb kuceb mentioned this issue Sep 6, 2019
6 tasks
@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: needs investigating Someone from Cypress needs to look at this labels Sep 6, 2019
@cypress-bot cypress-bot bot added stage: work in progress and removed stage: needs review The PR code is done & tested, needs review labels Sep 25, 2019
@jennifer-shehane
Copy link
Member

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.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 23, 2019

Released in 3.5.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants