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.

Uncaught Cypress: Return Promise Issue

See original GitHub issue

Current 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

image

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
aexolcommented, Jul 4, 2019

@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’

5reactions
jennifer-shehanecommented, Jun 10, 2019

Hey @priyankaghosh1989, I’m pretty sure the suspect code is the code below:

...
cy.get('button.action-btn')
setTimeout(() => {
  cy.get('.csLoaderExplainer').should('not.exist');
}, 60000);
cy.get('.page-item')
...

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.

Read more comments on GitHub >

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

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