I’m just learning testing in Mocha. By using esm import/export style I’m trying to test using Mocha the class that is in the path App/file-name.js and file where test code written is in the path test/folder-name/file-name.spec.js.
When I run the command from terminal
npm test
Exception during run: Error [ERR_MODULE_NOT_FOUND]: Cannot find module ‘C:UsersUserDesktopDEVTESTAutomated Testing in JSIntroduction to Unit Testingappnumbers_validator’ imported from C:UsersUserDesktopDEVTESTAutomated Testing in JSIntroduction to Unit Testingtestnumbers-validatorisNumberEven.spec.js
I get the following from the terminal
In the root folder I have this for mocha .mocharc.json with the content:
{
"spec": "test/**/*.spec.js",
"reporter": "mochawesome"
}
Eslint config file eslint.config.mjs
import config from "eslint-config-google";
export default [...[].concat(config)];
So like I don’t understand why is that happening I am using import and exports as
export class NumbersValidator {
import { expect } from "chai";
import { describe, beforeEach, afterEach, it } from "mocha";
import NumbersValidator from "../../app/numbers_validator";```
I tried all the ways get test working with require of commonjs and esm's import/export
prog_deude is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.