Cypress error Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.
Cypress commands aren't promises, and mixing them with real promises (async/await, fetch, .then returning a Promise) confuses its command queue.
Published
Why this happens
- A test or custom command is declared `async` and uses `await` alongside `cy.*` calls
- A `.then()` callback returns a native Promise and also calls `cy.*` inside it
- A helper uses `fetch` or an npm library that returns a Promise, then calls `cy` commands inside its resolution
How to fix it
- Remove `async`/`await` from Cypress tests and custom commands. Chain with `.then()` instead
- Move Node or Promise-based work (DB seeding, API setup, file reads) into a `cy.task()`, which Cypress waits on correctly
- Wrap an unavoidable Promise in `cy.wrap(promise)` and continue the chain from there, without calling `cy` inside the Promise itself
Example
// Bad
it('creates a user', async () => {
const user = await createUser();
cy.visit(`/users/${user.id}`);
});
// Good
it('creates a user', () => {
cy.task('createUser').then(user => {
cy.visit(`/users/${user.id}`);
});
});