question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 😃

screen shot 2018-02-19 at 16 05 04

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
probablyupcommented, Oct 1, 2018

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.

1reaction
brian-manncommented, Feb 19, 2018

This PR should fix this. Thank you for opening a good issue.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found