C. Using to.equal() instead of to.deep.equal() for object comparison
D. readFile cannot be used with JSON files
Solution
Step 1: Understand data type returned by readFile
Reading a JSON file returns an object, not a string.
Step 2: Check assertion method
to.equal() checks strict equality, which fails for objects; to.deep.equal() is needed for object content comparison.
Final Answer:
Using to.equal() instead of to.deep.equal() for object comparison -> Option C
Quick Check:
Use deep.equal for object assertions [OK]
Hint: Use deep.equal for objects, equal for primitives [OK]
Common Mistakes:
Using to.equal() for objects
Ignoring error handling
Assuming readFile can't read JSON
5. You want to verify that a text file notes.txt contains the word "important" anywhere in its content using Cypress. Which code snippet correctly performs this check?
hard
A. cy.readFile('notes.txt').then((text) => { expect(text.includes('important')).to.be.true; })
B. cy.readFile('notes.txt').should('contain', 'important')
C. cy.readFile('notes.txt').then((text) => { expect(text).to.equal('important'); })
D. cy.readFile('notes.txt').then((text) => { expect(text).to.have.property('important'); })
Solution
Step 1: Understand file content check
We want to check if the word "important" is anywhere in the text, so we need to check substring presence.
Step 2: Evaluate options
cy.readFile('notes.txt').then((text) => { expect(text.includes('important')).to.be.true; }) uses includes() and asserts true, which is correct. cy.readFile('notes.txt').should('contain', 'important') is invalid because should('contain') is for DOM elements, not file content. cy.readFile('notes.txt').then((text) => { expect(text).to.equal('important'); }) checks exact equality, which is wrong. cy.readFile('notes.txt').then((text) => { expect(text).to.have.property('important'); }) wrongly uses to.have.property() on a string.
Final Answer:
cy.readFile('notes.txt').then((text) => { expect(text.includes('important')).to.be.true; }) -> Option A
Quick Check:
Use includes() to check substring in file text [OK]
Hint: Use includes() inside then() to check text content [OK]
Common Mistakes:
Using should('contain') on file content
Checking exact equality instead of substring
Using property assertion on string
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.