Using trigger() in command specification leads to 'Cypress detected that you returned a promise' error
See original GitHub issueCurrent 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:
- Created 4 years ago
- Comments:5 (2 by maintainers)
I think your error come from the way you declare your
it
test and the use of theasync
keyword.According to cypress documentation there is no need for your
it
to be anasync
style function.This is probably why you see the ‘invoking from a promise’ error.
@seyfer could you try your
it
without theasync
keyword ? I think it should fix your error.@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.