Use a Fixture in Cypress to Provide Response Data to Network Requests

Filip Hric
InstructorFilip Hric
Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 3 years ago

Instead of explicitly providing the exact body, you can choose to save the data you want to use in a separate file. When you create a file in the fixtures folder, you can reference it using fixture option in the .intercept() command. This will automatically look into the fixtures folder and load the data from the file.

Filip Hric: [0:00] Instead of explicitly providing the body, I can choose to save my response data inside a fixture file. I have saved a fixture file inside my fixtures folder. To provide this file as a response, I can go back to my spec file and type fixture and then the name of my file, which should be customList.

[0:24] Cypress will automatically know that it should look for a customList file inside the fixtures folder. Now, when I save my test, I can see that the list is taken from my fixture file.

egghead
egghead
~ 10 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today