Mocha: ReferenceError: describe is not defined

Created on 21 Dec 2015  路  10Comments  路  Source: mochajs/mocha

Hello,

I'm currently using mocha v2.3.4, chai, and es6 with babel 6 and running in node v5.3.0.

This is my test script that I run with npm:
mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive

I have mocha globally installed, but whenever I run the test script I get the following output in my terminal:

ReferenceError: describe is not defined

Does anyone have any Ideas for why this may be happening?

unconfirmed-bug

Most helpful comment

I would like to open the same issue again. I'm upgrading an existing node project to Typescript. I'm receiving the same error when trying to run mocha for the following project specs:

  • Node
  • Typescript
  • ES6

I have all the @types needed installed (mocha, chai, node, supertest, etc) and adding the @types directory to the typeRoots of the TS compiler options in .tsconfig.json. This way I don't have to do import "mocha" at the beginning of my test

I have also installed ts-babel-node which sits on top of ts-node to transpile ES6 to ES5 in Node Typescript projects. This is working fine, however, it's unable to recognize describe during runtime only. The compiler is referencing the @types/mocha 's describe() definition but not when I run the tests.

.babelrc is defined too

Running the main app with ts-babel-node src/server.ts runs fine

Running tests with mocha -r ts-babel-node/bin/ts-babel-node test/test.ts fails in reading the describe() method.

I also tried running mocha --compilers js:ts-babel-node/bin/ts-babel-node test/test.ts

but with no luck.

Any tips would be appreciated

All 10 comments

I don't know _why_ this is happening, but see this SO question

this may be a mocha bug, or maybe you just can't do this anymore with babel 6, I dunno. someone should find out!

@boneskull thanks for the feedback but unfortunately I already have my .babelrc configured. Hopefully it isn't a big problem because I have to deliver the project I'm working on in the next few days.

@kennetpostigo then skip that step?

@boneskull I'm in charge of testing 馃槄

@kennetpostigo I have no idea what you're talking about.

@boneskull what did you mean by "then skip that step?"

@kennetpostigo

"unfortunately I already have my .babelrc configured"

then, as in the SO answer, skip creating .babelrc.

I would like to open the same issue again. I'm upgrading an existing node project to Typescript. I'm receiving the same error when trying to run mocha for the following project specs:

  • Node
  • Typescript
  • ES6

I have all the @types needed installed (mocha, chai, node, supertest, etc) and adding the @types directory to the typeRoots of the TS compiler options in .tsconfig.json. This way I don't have to do import "mocha" at the beginning of my test

I have also installed ts-babel-node which sits on top of ts-node to transpile ES6 to ES5 in Node Typescript projects. This is working fine, however, it's unable to recognize describe during runtime only. The compiler is referencing the @types/mocha 's describe() definition but not when I run the tests.

.babelrc is defined too

Running the main app with ts-babel-node src/server.ts runs fine

Running tests with mocha -r ts-babel-node/bin/ts-babel-node test/test.ts fails in reading the describe() method.

I also tried running mocha --compilers js:ts-babel-node/bin/ts-babel-node test/test.ts

but with no luck.

Any tips would be appreciated

mocha is a wrapper around node. _mocha is the "real" executable. try ts-babel-node _mocha <mocha options>

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wzup picture wzup  路  3Comments

eschwartz picture eschwartz  路  3Comments

luoxi001713 picture luoxi001713  路  3Comments

jamietre picture jamietre  路  3Comments

Aarbel picture Aarbel  路  3Comments