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

How to fix it

  1. Remove `async`/`await` from Cypress tests and custom commands. Chain with `.then()` instead
  2. Move Node or Promise-based work (DB seeding, API setup, file reads) into a `cy.task()`, which Cypress waits on correctly
  3. 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}`);
  });
});