Bird
0
0

Which of the following is the correct syntax to read a JSON file named data.json using Cypress?

easy📝 Syntax Q12 of 15
Cypress - File Operations
Which of the following is the correct syntax to read a JSON file named data.json using Cypress?
Acy.readFile('data.json', 'utf8')
Bcy.readFile('data.json').then((content) => { /* use content */ })
Ccy.readFile('data.json').catch((content) => { /* use content */ })
Dcy.readFile('data.json').write((content) => { /* use content */ })
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct method chaining

    Using then() after cy.readFile() is correct to access file content.
  2. Step 2: Check other options

    catch() is for errors, not normal reading; write() is invalid here; passing 'utf8' alone is incomplete.
  3. Final Answer:

    cy.readFile('data.json').then((content) => { /* use content */ }) -> Option B
  4. Quick Check:

    Use then() to handle readFile content [OK]
Quick Trick: Use then() to access file content after readFile [OK]
Common Mistakes:
  • Using catch() instead of then()
  • Trying to write after readFile
  • Passing encoding without then()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes