"Your callback function returned a promise which never resolved" error with cy.queryByText()
See original GitHub issuecypress-testing-library
version: 2.3.6node
version: 10.12.0npm
(oryarn
) 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:
- Created 5 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top 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 >
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
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)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*
tofind*
.query*
commands do not retry until success likefind*
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 becausequery*
never failed if it didn’t find what you were looking for. Ifquery*
failed to find an element, it would return an empty object. So the following would never fail before but does now:I think we’re safe to close this now. If this is still a problem for anyone please open a new issue. Thanks!