2

When I'm trying to run cypress test I'm getting this error:

The following error originated from your test code, not from Cypress.

\> Cannot find module './commands'

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.

Cypress could not associate this error to any specific test.

We dynamically generated a new test to display this failure.

I was expecting my tests to run, and I've tried to create an index.js in the support folder with:

import './commands'

Cypress.on('uncaught:exception', (err, runnable) => {
  return false;
})

But that doesn't seem to work.

1 Answer 1

0

When I had this issue it was because I tried to import from the wrong file.

Instead of importing in the test file, commands should be imported into /cypress/support/e2e(.js|.ts) file.

Ref Custom Commands

We recommend defining queries is in your cypress/support/commands.js file, since it is loaded before any test files are evaluated via an import statement in the supportFile.

That way they are available in any test that requires them. This is because the /cypress/support/e2e.js file is automatically integrated into the start of any and all test runs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.