Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting uncaught exception #7

Open
silroe opened this issue Jul 31, 2023 · 1 comment
Open

Getting uncaught exception #7

silroe opened this issue Jul 31, 2023 · 1 comment
Assignees

Comments

@silroe
Copy link

silroe commented Jul 31, 2023

Hi, @jakedowns

Im getting this exception:

(uncaught exception)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.click()

The cy command you invoked inside the promise was:

cy.openTab()

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

Cypress will resolve your command with whatever the final Cypress command yields.

The reason this is an error instead of a warning is because Cypress internally queues commands serially whereas Promises execute as soon as they are invoked. Attempting to reconcile this would prevent Cypress from ever resolving.

@nevcos
Copy link

nevcos commented Nov 7, 2023

In my case I need to test a page with a button that should open a popup.

The test clicks on the button this way:

cy.window().getById("open-popup").click();

Then the same error happens:

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.click()`

The cy command you invoked inside the promise was:

  > `cy.openTab()`

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

Cypress will resolve your command with whatever the final Cypress command yields.

The reason this is an error instead of a warning is because Cypress internally queues commands serially whereas Promises execute as soon as they are invoked. Attempting to reconcile this would prevent Cypress from ever resolving.
    at cy.<computed> [as openTab] (cypress_runner.js:160665:72)
    at Object.invoke (cypress_runner.js:128531:32)
    at functionStub (cypress_runner.js:131217:43)
    at Function.invoke (cypress_runner.js:130069:47)
    at agent.invoke (cypress_runner.js:144432:27)
    at windowOpen (cypress_runner.js:130329:26)

I'm setting the window.open stub in the following way:

cy.visit("/my-url", {
  onBeforeLoad(win) {
    cy.stub(win, "open", (url, target, features) => {
      cy.openTab(Cypress.config().baseUrl + url, {
        tab_name: "popup",
        window_features: features,
      });
      return true;
    }).as("windowOpen"); 
  }
});

@jakedowns jakedowns self-assigned this Dec 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants