Uncaught Cypress: Return Promise Issue
See original GitHub issueCurrent behavior:
I am facing very weird behavior in cypress… I have written a custom command in commands.js file, and using that command in spec file in different it function. The command passes in 1st 2 functions but fails in the third saying Uncaught CypressError: Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.
. Although I have never used Promise.
Desired behavior:
The function should behave consistently same.
Steps to reproduce: (app code and test code)
In Spec file:
it('[1]FunctionName', function() {
……
……
cy.filterByItemName(itemName);
});
it('[2]FunctionName', function() {
cy.filterByItemName(itemName);
……
……
});
it('[3]FunctionName', function() {
cy.filterByItemName(itemName);
……
……
});
In commands.js file:
Cypress.Commands.add('filterByItemName', itemName => {
cy.get('.cs-tag-list > .cs-tag-list__input').type('{backspace}' + itemName + '{enter}');
});
Versions
Cypress: 3.3.1 Mac Os
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Cypress.Promise
Cypress is promise aware so if you return a promise from inside of commands like .then() , Cypress will not continue until those...
Read more >Fix The Dreaded Cypress Error "Command Inside Of A Promise"
In this video, I explain the dreaded " Cypress detected that you returned a promise in a test, but also invoked one or...
Read more >How to fix warning "Cypress detected that you returned a ...
Remove async/await from your test. Cypress commands are not promises, although behaving like promises. Read more here.
Read more >TypeError: "x" is not a constructor - JavaScript - MDN Web Docs
When returning an immediately-resolved or immediately-rejected Promise, you do not need to create a new Promise(...) and act on it. Instead, use the...
Read more >Avoid Cypress warnings about mixing promise and cy ... - GitLab
API commands Now that https://github.com/cypress-io/cypress/issues/4790 is ... Cypress Warning: Cypress detected that you returned a promise in a test, ...
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 FreeTop 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
Top GitHub Comments
@jennifer-shehane Actually not. I found the real problem with this issue. It fires sometimes when the element is hidden underneath the other element. After many refactor of my own code and keeping up cypress best practices I still had that error.
So the main reason for this is Cypress just throwing this error message in different situations.
To repair this you need to implement more specific errors and find the place where try catch is used to ‘globally’
Hey @priyankaghosh1989, I’m pretty sure the suspect code is the code below:
This is being run completely outside of Cypress’s commands, so this command will be queued at 60 seconds within your test run - which, at that point - who knows what Cypress command is currently running?
I’d suggest reading through some of our core concepts that explain how the commands run here: https://on.cypress.io/introduction-to-cypress#Commands-Are-Asynchronous
Could you explain exactly what you are trying to achieve with the code above in the
setTimeout()
within the Cypress tests? There is likely a better way to achieve the same results - and prevent the Promise error you are getting.