Bird
0
0

What is wrong with this Cypress test code snippet?

medium📝 Debug Q7 of 15
Cypress - Plugins and Ecosystem
What is wrong with this Cypress test code snippet?
cy.task('deleteFile', 'temp.txt').then(() => {
  cy.task('deleteFile', 'temp.txt')
})
ATask names must be uppercase
BThe second <code>cy.task</code> is not chained with <code>then</code>
CTasks cannot be called twice in a test
DPassing string directly is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the chaining of tasks

    The first cy.task is chained with then, but the second is called without chaining or returning.
  2. Step 2: Understand Cypress command chaining

    All Cypress commands should be chained or returned to maintain execution order.
  3. Final Answer:

    The second cy.task is not chained with then -> Option B
  4. Quick Check:

    Chain all Cypress commands properly [OK]
Quick Trick: Chain all cy.task() calls with then() or return [OK]
Common Mistakes:
  • Calling Cypress commands without chaining
  • Assuming tasks run in parallel automatically
  • Incorrect task name casing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes