Bird
0
0

Identify the error in this Cypress test snippet:

medium📝 Debug Q6 of 15
Cypress - File Operations
Identify the error in this Cypress test snippet:
cy.downloadFile('https://example.com/data.json', 'cypress/downloads/data.json')
cy.readFile('cypress/downloads/data.json').should('eq', '{"key":"value"}')
AIncorrect file path syntax
BMissing cy.visit() before downloadFile
CUsing 'eq' instead of 'deep.equal' for JSON content comparison
DNo error, the code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Understand assertion for JSON content

    Using 'eq' compares strings exactly, but JSON objects require deep equality check.
  2. Step 2: Identify correct assertion

    For JSON content, use .should('deep.equal', {"key":"value"}) instead of string comparison.
  3. Final Answer:

    Using 'eq' instead of 'deep.equal' for JSON content comparison -> Option C
  4. Quick Check:

    JSON content needs deep equality, not string eq [OK]
Quick Trick: Use deep.equal for JSON object assertions [OK]
Common Mistakes:
  • Comparing JSON as strings with 'eq'
  • Assuming cy.visit() is needed before downloadFile

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes