Cypress will not stop test run if errors in before hook
See original GitHub issue- Operating System: osx
- Cypress Version: 2.0.2
- Browser Version: Canary 66
Is this a Feature or Bug?
Bug
Current behavior:
If an error is raised in the before hook for tests, Cypress will not stop the test run and seems to continue indefinitely.
This behaviour seems identical to #674
Desired behavior:
Tests should fail with a descriptive error message.
How to reproduce:
Run the below code
Test code:
describe('Demo throw in before hook', () => {
before(() => {
cy.exec('echo "test test"').then(() => {
throw new Error('whoa something broke');
});
});
it('visits url', () => {
cy.get('/');
});
// NB: for some reason if I comment out the below test
// Cypress UI will fail the test correctly.
it('gets element', () => {
cy.get('.someelem');
});
});
Additional Info (images, stack traces, etc)
Below is a screenshot that shows that although the error is thrown, the spinner still continues to… spin 😃
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (8 by maintainers)
Top Results From Across the Web
Error Messages | Cypress Documentation
Test File Errors No tests found This message means that Cypress was unable to find tests in the specified file. You'll likely get...
Read more >Cypress: interrupt all tests on first failure - Stack Overflow
But it doesn't work: tests keep running after error. My guess is that Cypress will throw an error only when all tests are...
Read more >Cypress Best Practices For Test Automation - LambdaTest
Cypress is amazing overall, but if you don't do it the right way and ... page must work before any other specific page...
Read more >cypress-io/cypress - Gitter
And how does it not work, does it error or does nothing happen? ... In the before hooks i want to specify to...
Read more >Mocha - the fun, simple, flexible JavaScript test framework
Mocha is a feature-rich JavaScript test framework running on Node.js and in the ... If a hook is given a named function, that...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

FWIW I’m seeing this in “run” mode as well as a result of a page timeout during before. The screenshot gets written but the process never exits.
This PR should fix this. Thank you for opening a good issue.