Fixtures
Explore how to leverage Cypress fixtures in UI integration testing to separate backend mock responses from test code. Learn to organize fixture files and reference them in intercepts to create cleaner, more maintainable test scripts that stub backend calls effectively.
We'll cover the following...
We'll cover the following...
Introduction
Let’s take a look at the following test:
In the above test, every back-end stub has the response set inline, like the api/users stub:
cy.intercept("POST", "**/api/users", {
body: {
user: {
username: "Tester",
email: "user@realworld.io",
token:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVkN2ZhZjc4YTkzNGFiMDRhZjRhMzE0MCIsInVzZXJuYW1lIjoidGVzdGVyNzk1MzYiLCJleHAiOjE1NzM4MzY2ODAsImlhdCI6MTU2ODY0OTA4MH0.zcHxMz2Vx5h-EoiUZlRyUw0z_A_6AIZ0LzQgROvsPqw"
}
},
headers: { "Access-Control-Allow-Origin": "*" }
}).as("signup-request");
...