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

Intermittent erroneous error about calling a child command before running a parent command #30522

Open
jpage-godaddy opened this issue Nov 1, 2024 · 1 comment
Labels
type: user experience Improvements needed for UX

Comments

@jpage-godaddy
Copy link

Current behavior

I'm occasionally getting an error in my test suite. I have a beforeEach hook like this:

    beforeEach(function () {
      cy.intercept('GET', `/some/api/endpoint`, { statusCode: 200, body: [] })
        .as('getAppSettings');
    });

...and sometimes I get a failure like this:

The following error originated from your test code, not from Cypress. It was caused by an unhandled promise rejection.

> Oops, it looks like you are trying to call a child command before running a parent command.

You wrote code that looks like this:

cy.as("getAppSettings")

A child command must be chained after a parent because it operates on a previous subject.

Clearly something else is going on because I am not doing what the error says I'm doing. It seems like an unhandled exception occurring in the prior test causing an error to be misidentified. If I skip the prior test, this does not occur.

Desired behavior

Cypress should show the actual unhandled exception

Test code to reproduce

I cannot reproduce in a minimal enough way to share the full code.

Cypress Version

13.15.1

Node version

20.18.0

Operating System

Ubuntu 22.04.4 LTS

Debug Logs

I didn't see any debug output relating to this issue.

Other

I think the uncaught exception is due to an error being thrown in the browser after a previous test has completed, and that is being caught by the next test and erroneously associated with the currently executing command.

@jpage-godaddy
Copy link
Author

Actually, this may be even simpler. It looks like in this test suite, someone erroneously made their test block an async function which I know is incorrect. Changing that fixes the issue. Maybe Cypress can detect if a Promise is returned when running a test and tell the user that they should not be using an an async function.

@jennifer-shehane jennifer-shehane added the type: user experience Improvements needed for UX label Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: user experience Improvements needed for UX
Projects
None yet
Development

No branches or pull requests

2 participants