Test Overview
This test reads a JSON file using cy.readFile() and verifies that the file contains expected data. It checks the presence and correctness of specific keys and values.
This test reads a JSON file using cy.readFile() and verifies that the file contains expected data. It checks the presence and correctness of specific keys and values.
describe('Read JSON file and assert contents', () => { it('should read the file and verify its content', () => { cy.readFile('cypress/fixtures/user.json').then((data) => { expect(data).to.have.property('name', 'Alice'); expect(data).to.have.property('age').that.is.a('number'); expect(data.hobbies).to.include('reading'); }); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Cypress test runner is ready | - | PASS |
| 2 | Cypress opens test environment | Browser window opens with Cypress test runner UI | - | PASS |
| 3 | cy.readFile('cypress/fixtures/user.json') is called | File 'user.json' is accessed in fixtures folder | File is successfully read and parsed as JSON | PASS |
| 4 | Assertion: expect(data).to.have.property('name', 'Alice') | Data object contains key 'name' with value 'Alice' | Check that 'name' property equals 'Alice' | PASS |
| 5 | Assertion: expect(data).to.have.property('age').and.be.a('number') | Data object contains key 'age' with a numeric value | Check that 'age' property exists and is a number | PASS |
| 6 | Assertion: expect(data.hobbies).to.include('reading') | Data object has 'hobbies' array including 'reading' | Check that 'reading' is included in hobbies array | PASS |
| 7 | Test ends | All assertions passed, test completes successfully | - | PASS |