Babel/Mocha: Mocha installed globally but describe

2019-08-01 01:04发布

问题:

I'm trying to run a test and I'm getting this error:

/dev/tests/counters.spec.js:12
describe('Work damn you!', function () {
^

ReferenceError: describe is not defined

Mocha is installed both globally and locally to the project. I'm not sure if I've got it right, but this is my test script:

"test": "mocha --compilers js:babel-register --require dev/tests/counters.spec.js"

Am I going anything that's plainly wrong? Any help would be welcome.

回答1:

Try this configuration in package.json:

{
  // ...
  "test": "mocha dev/tests/counters.spec.js --compilers js:babel-register"
  // ...
}

The --require option is used to include modules like should, but not the unit test files. See more about this option.