0
0
Cypresstesting~5 mins

JSON fixture files in Cypress - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a JSON fixture file in Cypress?
A JSON fixture file is a simple file that stores test data in JSON format. Cypress uses it to load data during tests, making tests cleaner and easier to maintain.
Click to reveal answer
beginner
How do you load a JSON fixture file in a Cypress test?
Use cy.fixture('filename').then((data) => { ... }) to load the JSON data from the fixture file named filename.json.
Click to reveal answer
beginner
Why use JSON fixture files instead of hardcoding test data?
Using JSON fixture files keeps test data separate from test code. This makes tests easier to read, update, and reuse, just like keeping your recipe separate from your cooking steps.
Click to reveal answer
beginner
Where should JSON fixture files be placed in a Cypress project?
They should be placed inside the cypress/fixtures folder. Cypress automatically looks here when you use cy.fixture().
Click to reveal answer
beginner
What is the correct format for a JSON fixture file?
A JSON fixture file must be valid JSON: key-value pairs inside curly braces, with keys and string values in double quotes, and no trailing commas.
Click to reveal answer
Where do you place JSON fixture files in a Cypress project?
Acypress/integration
Bcypress/support
Ccypress/fixtures
Dcypress/plugins
How do you access data from a JSON fixture file in a test?
Acy.load('filename')
Bcy.fixture('filename').then((data) => { ... })
Ccy.readFile('filename.json')
Dcy.get('filename')
Why is it better to use JSON fixture files instead of hardcoding data?
AIt makes tests slower
BIt requires more code
CIt hides test data from the tester
DIt separates data from test code for easier maintenance
Which of these is a valid JSON fixture file content?
A{ "name": "Alice", "age": 30 }
B{ name: "Alice", age: 30 }
C{ 'name': 'Alice', 'age': 30 }
D{ name: 'Alice', age: 30 }
What happens if you try to load a fixture file that does not exist?
ACypress throws an error and fails the test
BCypress silently ignores it
CCypress creates an empty fixture file
DCypress retries loading automatically
Explain how to use JSON fixture files in Cypress tests.
Think about where the file goes and how to load it in your test.
You got /4 concepts.
    Describe the benefits of using JSON fixture files for test data.
    Consider how separating data helps in real life, like keeping ingredients separate from cooking steps.
    You got /4 concepts.