Cypress error cy.task('seedDb') failed with the following error: The task 'seedDb' was not handled in the setupNodeEvents method.
The spec called a task by name, but nothing registered a handler with that exact name in the Cypress config.
Published
Why this happens
- The task was never registered with `on('task', { ... })` inside `setupNodeEvents`
- The name used in `cy.task()` doesn't exactly match the key in the `on('task')` object (typo or different casing)
- `on('task', ...)` is called more than once, and a plugin's call replaced your task map instead of merging with it
- The config was changed while Cypress was open and the Node process hasn't reloaded it
How to fix it
- Register the task in `setupNodeEvents` in cypress.config.ts and check the key matches the name in `cy.task()`
- Merge all tasks into a single `on('task', { ...pluginTasks, ...yourTasks })` call rather than calling `on('task')` from several plugins
- Make sure the handler returns a value or `null`, never `undefined`, or Cypress will fail the task for a different reason
- Restart Cypress after editing the config file
Example
// cypress.config.ts
export default defineConfig({
e2e: {
setupNodeEvents(on) {
on('task', {
async seedDb() {
await resetDatabase();
return null; // tasks must not return undefined
},
});
},
},
});