Bird
0
0

Which syntax correctly defines a Cypress plugin function in the plugins file?

easy📝 Syntax Q3 of 15
Cypress - Plugins and Ecosystem
Which syntax correctly defines a Cypress plugin function in the plugins file?
Aconst plugin = (on, config) => { return on('task', { myTask() { return null } }) }
Bexport default function(on, config) { on('task', { myTask() { return null } }) }
Cmodule.exports = (on, config) => { on('task', { myTask() { return null } }) }
Dfunction plugin(on, config) { on('task', { myTask() { return null } }) }
Step-by-Step Solution
Solution:
  1. Step 1: Recall Cypress plugin export syntax

    Cypress plugins use CommonJS syntax with module.exports to export the function.
  2. Step 2: Analyze options for correct syntax

    module.exports = (on, config) => { on('task', { myTask() { return null } }) } uses module.exports with arrow function and correct event handler setup. The other options fail: one defines a local const without export, another uses ES module export, and the last lacks any export.
  3. Final Answer:

    module.exports = (on, config) => { on('task', { myTask() { return null } }) } -> Option C
  4. Quick Check:

    Plugin export = module.exports function [OK]
Quick Trick: Use module.exports for Cypress plugins [OK]
Common Mistakes:
  • Using ES module export instead of CommonJS
  • Not exporting the plugin function
  • Returning inside the plugin function incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes