Bird
0
0

Identify the error in this test code:

medium📝 Debug Q6 of 15
Cypress - File Operations
Identify the error in this test code:
cy.readFile('users.json').should('have.property', 'name', 'John')

Assuming users.json contains an array of user objects.
Ahave.property cannot be used on arrays directly
BThe file path is incorrect
CThe assertion syntax is invalid
Dcy.readFile cannot read JSON files
Step-by-Step Solution
Solution:
  1. Step 1: Understand the file content type

    The file contains an array, not an object with property 'name'.
  2. Step 2: Analyze assertion applicability

    have.property works on objects, not arrays directly, so this causes a logical error.
  3. Final Answer:

    have.property cannot be used on arrays directly -> Option A
  4. Quick Check:

    have.property requires object, not array [OK]
Quick Trick: Use array assertions or access elements before property checks [OK]
Common Mistakes:
  • Using have.property on arrays
  • Assuming JSON files can't be read
  • Incorrect file path assumptions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes