'Receiving The 'task' event has not been registered in the plugins file. You must register it before using cy.task()

I don't know how to use the task and for which purpose, I have one project and I have got this project for solving errors. and I am getting this error. Any help or suggestions are welcome.

I have this code in my plugins/index.js file.

module.exports = (on, config) => {
on("task", { "setUserId": (val) => { return (userId = val); }});
};

And in my test i have implement like this. cy.task('setUserId', randomEmail);

I got this below error.

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source