Bird
0
0

Given the code below, what will be logged to the console if example.txt contains the text "Hello Cypress"?

medium📝 Predict Output Q13 of 15
Cypress - File Operations
Given the code below, what will be logged to the console if example.txt contains the text "Hello Cypress"?
cy.readFile('example.txt').then((text) => {
  console.log(text);
});
AEmpty string
Bundefined
CAn error because readFile needs JSON
D"Hello Cypress"
Step-by-Step Solution
Solution:
  1. Step 1: Understand readFile behavior

    cy.readFile() reads file content as text by default if file is plain text.
  2. Step 2: Check the file content

    The file contains "Hello Cypress", so the callback receives this string and logs it.
  3. Final Answer:

    "Hello Cypress" -> Option D
  4. Quick Check:

    readFile logs file text content [OK]
Quick Trick: readFile returns file content as string for text files [OK]
Common Mistakes:
  • Assuming readFile only works with JSON
  • Expecting undefined instead of content
  • Thinking it throws error for text files

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes