Bird
0
0

Consider this plugin code:

medium📝 Predict Output Q4 of 15
Cypress - Plugins and Ecosystem
Consider this plugin code:
module.exports = (on, config) => {
  on('task', {
    echo(text) {
      console.log(text)
      return text
    }
  })
}

What will cy.task('echo', 'Test') return in the test?
AReturns 'Test' and logs 'Test' to the console
BReturns null and logs 'Test' to the console
CReturns undefined and logs nothing
DThrows an error because return is missing
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the task function

    The 'echo' task logs the input text and returns it.
  2. Step 2: Understand cy.task behavior

    cy.task resolves with the returned value from the plugin task.
  3. Final Answer:

    Returns 'Test' and logs 'Test' to the console -> Option A
  4. Quick Check:

    Return value is passed back to test, console logs side effect [OK]
Quick Trick: Return value from task is sent back to test [OK]
Common Mistakes:
  • Assuming console.log output is returned
  • Forgetting to return a value from the task
  • Confusing return null with undefined

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes