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.

"Your callback function returned a promise which never resolved" error with cy.queryByText()

See original GitHub issue
  • cypress-testing-library version: 2.3.6
  • node version: 10.12.0
  • npm (or yarn) version: 6.4.1

I have a few tests checking that an elements doesn’t exist using a command like

cy.queryByText("xxxxxxx", { timeout: 300 }).should("not.exist");

Usually, everything is fine. But, occasionally, I get a failure like this:

     CypressError: cy.then() timed out after waiting '400ms'.

Your callback function returned a promise which never resolved.

The callback function was:

function Command__queryByText(thenArgs) {
              return commandImpl(thenArgs.document)
            }
      at Object.cypressErr (http://xxx.xxx.xxx:8084/__cypress/runner/cypress_runner.js:65283:11)
      at Object.throwErr (http://xxx.xxx.xxx:8084/__cypress/runner/cypress_runner.js:65248:18)
      at Object.throwErrByPath (http://xxx.xxx.xxx:8084/__cypress/runner/cypress_runner.js:65275:17)
      at http://xxx.xxx.xxx:8084/__cypress/runner/cypress_runner.js:54007:21
      at tryCatcher (http://xxx.xxx.xxx:8084/__cypress/runner/cypress_runner.js:127195:23)
      at http://xxx.xxx.xxx:8084/__cypress/runner/cypress_runner.js:122505:41
      at tryCatcher (http://xxx.xxx.xxx:8084/__cypress/runner/cypress_runner.js:127195:23)
      at Promise._settlePromiseFromHandler (http://xxx.xxx.xxx:8084/__cypress/runner/cypress_runner.js:125213:31)
      at Promise._settlePromise (http://xxx.xxx.xxx:8084/__cypress/runner/cypress_runner.js:125270:18)
      at Promise._settlePromise0 (http://xxx.xxx.xxx:8084/__cypress/runner/cypress_runner.js:125315:10)
      at Promise._settlePromises (http://xxx.xxx.xxx:8084/__cypress/runner/cypress_runner.js:125390:18)
      at Async._drainQueue (http://xxx.xxx.xxx:8084/__cypress/runner/cypress_runner.js:122119:16)
      at Async._drainQueues (http://xxx.xxx.xxx:8084/__cypress/runner/cypress_runner.js:122129:10)
      at Async.drainQueues (http://xxx.xxx.xxx:8084/__cypress/runner/cypress_runner.js:122003:14)
      at <anonymous>

I nailed it down to the timeout on https://github.com/kentcdodds/cypress-testing-library/blob/master/src/index.js#L53 , and everything seems to work if we remove the timeout option.

Since waitForElement is already called with a timeout option on https://github.com/kentcdodds/cypress-testing-library/blob/master/src/index.js#L24 , is it needed on the cypress command chain? Could it be removed from that line 53?

Sorry for not providing a code sample, but I have not been able to reliably reproduce it.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
NicholasBollcommented, Feb 3, 2020

I’m a little late to the party. I introduced some changes to the way these Cypress Custom commands work. Is this still an issue in 5.2.1?

I know for sure the original error shouldn’t happen, because the .then was removed in #108 (lines here: https://github.com/testing-library/cypress-testing-library/pull/108/files#diff-1fdf421c05c1140f6d71444ea2b27638L75-L77)

In fact, since moving to 5.0.0 I’m seeing these failures when I wasn’t before. Unhelpfully, I now no longer which command actually failed.

Hopefully this is no longer an issue. That’s what #108 sought to address - better debugging of failures.

My recommendation is to change all query* to find*. query* commands do not retry until success like find* queries do and like all other built-in Cypress commands. They will pass or fail almost instantly. They also can be a little flaky because technically in @testing-library/dom query* commands are synchronous and all Cypress commands are asynchronous. query* queries try to mimic synchronous behavior by executing asap and not retrying. If your application is a bit slower for whatever reason, query could fail.

The changes introduced in 5.2.1 could fail where previously they passed, but not because the previous logic was correct, but because query* never failed if it didn’t find what you were looking for. If query* failed to find an element, it would return an empty object. So the following would never fail before but does now:

cy.queryByText('Does not exist').should('exist')
0reactions
kentcdoddscommented, Feb 4, 2020

I think we’re safe to close this now. If this is still a problem for anyone please open a new issue. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Your callback function returned a promise that never resolved
Hii Team, I am working to programmatically login to Okta using Cypress. Getting error, Can you please help. Cypress.
Read more >
Cypress function randomly times out "promise that never ...
cy.then() timed out after waiting 4000ms. Your callback function returned a promise that never resolved. My function is: Cypress ...
Read more >
cypress-io/cypress - Gitter
I get this error. CypressError: cy.then() timed out after waiting '8000ms'. Your callback function returned a promise which never resolved.
Read more >
Async Methods - Testing Library
The async methods return Promises, so be sure to use await or .then when calling them. ... Wait until the callback does not...
Read more >
Testing-library: avoid these mistakes in async tests
Never forget to await for async functions or return promises from the test (jest will wait for this promise to be resolved in...
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