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.

Nesting hooks within other hooks causes the test to never finish (runs forever)

See original GitHub issue

Current behavior:

Since upgrading to Cypress 5.0.0, I cannot get any tests to pass. Tests will run through all the code, but when they get to the end, the test does not get marked as passed and the timer keeps counting up.

image

Desired behavior:

Tests end and move on the next test/spec.

Test code to reproduce

context('Never-ending Test', function () {
  it('Test', function () {
    cy.visit('http://wikipedia.com')
    cy.get('#searchInput')
      .type('Cypress.io')
    cy.get('.pure-button')
      .click()
    // Test never ends.
  })

  it('Next Test', function () {
    // Test never starts.
    cy.visit('http://wikipedia.com')
  })
})

Versions

Cypress 5.0.0 macOS: 10.14.6 Browser: Chrome 84.0.4147.125, Firefox 79, Electron 83

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
bahmutovcommented, Aug 20, 2020

@todd-m-kemp I thought how to extend our recipe to allow setting global test timeout, here is the solution https://github.com/cypress-io/cypress-example-recipes/pull/549

1reaction
todd-m-kempcommented, Aug 20, 2020

@Bkucera : Thank you so much for that explanation; I’ve tested it out and it does appear that is exactly what is happening. 😄 I’ll have to rework that section of code to remove the nested hook if the result here is that nested hooks soon won’t be supported.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Infinite loop in useEffect - reactjs - Stack Overflow
Passing an empty array as the second argument to useEffect makes it only run on mount and unmount, thus stopping any infinite loops....
Read more >
Avoid Nesting when you're Testing - Kent C. Dodds
Why using hooks like beforeEach as a mechanism for code reuse leads to unmaintainable tests and how to avoid it.
Read more >
How to solve the React useEffect Hook's infinite loop patterns
Solve the issue of infinite loops when using the useEffect Hook in React to more smoothly utilize the Hook for your app's side...
Read more >
How To Handle Async Data Loading, Lazy Loading, and Code ...
This will let you run your asynchronous code deliberately instead of on ... In this step, you'll use the useEffect Hook to load...
Read more >
Changelog - Cypress Documentation
Fixed an issue where the Cypress migration wizard would fail to run in global ... where nesting hooks within other hooks caused the...
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