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);
});- 1
importthe fixture inside the support file only - 2
cy.fixturewith.then, or alias it with.as() - 3Fixtures can only be used with
cy.intercept
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.