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.');
});
});
Notice how the test has been running for almost 14 minutes.
This code should not cause Cypress to hang.
Cypress 3.1.0
Windows 10
Electron 59
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
.