Bird
0
0

Find the issue in this test snippet:

medium📝 Debug Q7 of 15
Cypress - File Operations
Find the issue in this test snippet:
cy.readFile('log.txt').should('contain', 404)

Assuming log.txt is a text file containing error codes as strings.
Acontain assertion is invalid here
BreadFile cannot read text files
CThe file path must be absolute
DThe assertion should check for string '404', not number 404
Step-by-Step Solution
Solution:
  1. Step 1: Understand file content type

    log.txt contains text, so numbers appear as strings.
  2. Step 2: Analyze assertion argument type

    Checking for number 404 will fail; it should be string '404' to match text content.
  3. Final Answer:

    The assertion should check for string '404', not number 404 -> Option D
  4. Quick Check:

    Match types: text content needs string in assertions [OK]
Quick Trick: Match assertion value type to file content type [OK]
Common Mistakes:
  • Using number instead of string for text files
  • Thinking readFile can't read text
  • Assuming absolute path is required

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes