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.

Using trigger() in command specification leads to 'Cypress detected that you returned a promise' error

See original GitHub issue

Current behavior:

Cypress missing the hover() method for some reason. https://github.com/cypress-io/cypress/issues/10

I have added my own implementation with use of trigger() as it is recommended in docs. https://on.cypress.io/trigger

Cypress.Commands.add('hover', {prevSubject: 'element'}, subject => {
    cy.get(subject.selector).trigger('mouseover');
});

But when I use it

cy.get('#some').hover();

I get this error from the docs https://on.cypress.io/error-messages#Cypress-detected-that-you-returned-a-promise-from-a-command-while-also-invoking-one-or-more-cy-commands-in-that-promise

CypressError: Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.

The command that returned the promise was:

  > cy.trigger()

The cy command you invoked inside the promise was:

  > cy.task()

Because Cypress commands are already promise-like, you don't need to wrap them or return your own promise.

In my case this hover works, I can see it hovering in the test runner. But I have an animation to show up some children element on hover. Probably it is considered as Promise for Cypress? Because I do not return it explicitly anywhere.

Desired behavior:

https://github.com/cypress-io/cypress/issues/10 resolved or at least Cypress doesn’t react to trigger() side effects or any other workaround possible.

Steps to reproduce: (app code and test code)

Described in the description.

Versions

Latest Cypress (3.7.0), latest Chrome from deb repositories, Debian.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
avalletecommented, Dec 1, 2019

I think your error come from the way you declare your it test and the use of the async keyword.

According to cypress documentation there is no need for your it to be an async style function.

This is probably why you see the ‘invoking from a promise’ error.

@seyfer could you try your it without the async keyword ? I think it should fix your error.

0reactions
seyfercommented, Dec 17, 2019

@avallete I started to use Cypress Cucumber plugin and with new syntaxis, the issue disappeared from errors, but still outputs in the browser dev tools console as a warning.

In my example, I just forgot to remove async, sorry. It still was failing without it. Anyway, the issue was kind of solved with Cucumber plugin.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error Messages | Cypress Documentation
Cypress detected that you invoked one or more cy commands but returned a different value. Cypress detected that you returned a promise from...
Read more >
Getting 'Cypress detected that you returned a promise from a ...
This is an error instead of a warning because Cypress internally queues commands serially whereas Promises execute as soon as they are invoked....
Read more >
Using trigger() in command specification leads to 'Cypress detected ...
Using trigger () in command specification leads to 'Cypress detected that you returned a promise' error.
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 >
cypress-io/cypress - Gitter
The command passes in 1st 2 functions but fails in the third saying "Uncaught CypressError: Cypress detected that you returned a promise from...
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