Cypress · Middle · Question 59 of 77

How do you load a fixture and use it in assertions?

cy.fixture("user.json").then((user) => {
  cy.get("[data-cy=name]").should("have.text", user.name);
});
Show the answer

Correct answer: cy.fixture with .then, or alias it with .as()

Explanation

Aliasing with .as('user') and this.user also works in function () {} tests.

Further reading

Problem with a question

Cypress · Middle · question 59

Test yourself

Take the Cypress · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz