cypress: Error: The 'task' event has not been registered in the plugins file. You must register it before using cy.task()
Current behavior:
I copied steps from https://github.com/cypress-io/cypress/issues/2284 with slight modification.
in my spec:
cy.task('seedRisks',{"model": "delete"})
in index.js:
module.exports = (on) => {
on('task:requested', (event, arg) => {
switch (event) {
case 'seedRisks': {
console.log('sdjdsj'); //just a placeholder
}
}
})
}
When I run my tests, getting error:
CypressError: cy.task('seedRisks') failed with the following error:
The 'task' event has not been registered in the plugins file. You must register it before using cy.task()
Fix this in your plugins file here:
C:\Users\Maxim.Karpov\cypress\plugins\index.js
https://on.cypress.io/api/task
Desired behavior:
want to be able to proceed without an error
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (4 by maintainers)
@J-QA Check your
cypress.jsonfor"pluginsFile": false. That keeps the plugins file from being loaded. That’s why the error messaging says:falseis where the path to the plugins file would be displayed if it was loaded.Remove
"pluginsFile": falsefromcypress.jsonandcy.task()should work.Looks like we could improve the error message for this case and make it clear that
cy.task()won’t work because the plugins file has been disabled.What was the issue?
I am facing same issue! total crap!
It worked like a charm, thank you @chrisbreiding for the quick response!
If you’re facing this issue:
tasksignature here: https://on.cypress.io/task#UsageAlso, check out our community chat, it can be helpful for debugging or answering questions on how to use Cypress.
I had a similar issue, I solved it by specifying my file in the cypress.json like so:
{ "pluginsFile": "./cypress/plugins/index.cjs" }I think by default cypress looks for a
.jsfile, and not.cjsor.ts.I get the same error with cypress 8.2.0. My cypres.json does not have pluginsFile: false also. Not sure where I am making a mistake:
I was getting this issue as well when creating tasks for the first time in my project. It seems like restarting the cypress instance is needed after making some changes in the plugin file (node process side).