Using Cypress fixtures to provide mock data
When it comes to writing E2E tests, fixtures play a great role in making sure the tests are not flaky. Consider that your tests rely on fetching data from your API server or your tests include snapshot testing, which includes fetching images from a content delivery network (CDN) or a third-party API. Although they're technically required for the tests to run successfully, it is not important that the server data and the images are fetched from the original source, therefore we can create fixtures for them. In this recipe, we'll create fixtures for the users' data as well as for the images to be shown on the UI.
Getting ready
The project that we are going to work with resides in chapter11/start_here/using-cypress-fixtures
, inside the cloned repository:
- Open the project in VS Code.
- Open the terminal and run
npm install
to install the dependencies of the project. - Once done, run
npm run cypress:test
.
...