Bird
0
0

Given this plugin code, what will be the output when the task 'greet' is called?

medium📝 Predict Output Q4 of 15
Cypress - Plugins and Ecosystem
Given this plugin code, what will be the output when the task 'greet' is called?
module.exports = (on) => {
  on('task', {
    greet(name) {
      return `Hello, ${name}!`
    }
  })
}
AError: greet is not a function
Bundefined
C"greet called"
D"Hello, Cypress!"
Step-by-Step Solution
Solution:
  1. Step 1: Understand the plugin task definition

    The plugin defines a task named 'greet' that returns a greeting string with the passed name.
  2. Step 2: Predict output when calling greet('Cypress')

    Calling greet with 'Cypress' returns the string "Hello, Cypress!" as per the template literal.
  3. Final Answer:

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

    Task output = formatted greeting string [OK]
Quick Trick: Plugin tasks return values synchronously [OK]
Common Mistakes:
  • Expecting undefined return
  • Confusing task name with function name
  • Assuming error without calling task properly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes