A. Pass because the file content matches the object exactly
B. Fail because the object keys are strings in the file
C. Fail because 'deep.equal' cannot compare objects
D. Pass but only if the file is a string, not JSON
Solution
Step 1: Understand deep.equal assertion
This assertion checks if two objects have the same structure and values deeply.
Step 2: Check if cy.readFile() parses JSON automatically
Yes, it parses JSON files into objects, so the assertion compares objects correctly.
Final Answer:
Pass because the file content matches the object exactly -> Option A
Quick Check:
deep.equal compares objects deeply [OK]
Hint: Use deep.equal to compare JSON objects, not strings [OK]
Common Mistakes:
Thinking file content is a string, not parsed JSON
Confusing deep.equal with shallow equal
Assuming keys must be non-string
4. What is wrong with this Cypress test code?
cy.readFile('log.txt').should('include', 'Error')
medium
A. The file must be JSON to use should assertions
B. The file path must be absolute, not relative
C. The assertion method should be 'contain', not 'include'
D. The method 'include' is correct and will pass if 'Error' is found
Solution
Step 1: Check the assertion method name
Cypress uses 'contain' for substring assertions; 'include' is not a valid assertion method.
Step 2: Confirm correct assertion for substring
The correct method is 'contain' to check if text includes a substring.
Final Answer:
The assertion method should be 'contain', not 'include' -> Option C
Quick Check:
Use 'contain' for substring assertions, not 'include' [OK]
Hint: Use 'contain' for substring checks, not 'include' [OK]
Common Mistakes:
Using 'include' instead of 'contain'
Thinking relative paths are invalid
Assuming only JSON files can be read
5. You want to verify a downloaded CSV file contains the header row exactly as "Name,Age,Email". Which Cypress code correctly reads the file and asserts this?
hard
A. cy.readFile('downloads/data.csv').should('contain', 'Name,Age,Email')
B. cy.readFile('downloads/data.csv').should('equal', 'Name,Age,Email')
C. cy.readFile('downloads/data.csv').should('deep.equal', 'Name,Age,Email')
D. cy.readFile('downloads/data.csv').should('include', 'Name,Age,Email')
Solution
Step 1: Understand the file content and assertion needed
The CSV file is text, and we want to check if it contains the exact header row as a substring.
Step 2: Choose the correct assertion for substring in text files
contain is the correct assertion to check if the file text includes the header row.
Final Answer:
cy.readFile('downloads/data.csv').should('contain', 'Name,Age,Email') -> Option A
Quick Check:
Use 'contain' to check text includes header row [OK]
Hint: Use 'contain' to check CSV header text inside file [OK]
Common Mistakes:
Using 'equal' which requires exact full file match
Using 'deep.equal' which is for objects, not strings
Using 'include' which is not a valid assertion
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.