How to resolve it?
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.visit()
The cy command you invoked inside the promise was:
cy.setCookie()
/// <reference types="cypress" />
import { internet, name } from "faker";
import "cypress-localstorage-commands";
const email = internet.exampleEmail();
const password = internet.password();
const first_name = name.firstName();
const last_name = name.lastName();
let user;
before(function registerUser() {
cy.request("POST", "https://api.domain.io/api/users/", {
first_name: first_name,
last_name: last_name,
email: email,
password: password,
})
.its("body")
.then((res) => {
user = res;
});
});
beforeEach(function setUser() {
cy.visit("https://app.domain.io/projects/create", {
onBeforeLoad: (win) => {
cy.setCookie("token", user.token);
},
});
});
describe("JWT", () => {
it("create project", () => {
cy.get('[type="text"]').type("Autotest project");
cy.get('[type="submit"]').click();
});
});
I managed to resolve it this way:
beforeEach(function setUser() {
cy.setCookie("token", user.token);
cy.visit("https://app.domain.io/projects/create");
});