ReferenceError: describe is not defined

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
boneskullcommented, Jun 7, 2017

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

2reactions
mhdatiecommented, Jun 7, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - ReferenceError: describe is not defined NodeJs
Assuming you are testing via mocha , you have to run your tests using the mocha command instead of the node executable.
Read more >
"ReferenceError: describe is not defined" on next build #34249
"ReferenceError: describe is not defined" on next build. ... { type: 'ReferenceError' } error Command failed with exit code 1.
Read more >
Test Runner/Debugger ReferenceError: describe is not defined
Test produces a ReferenceError saying 'describe is not defined'. It is as if the test runner no longer recognized that mocha is installed...
Read more >
Jest reference error 'describe' is not defined when running ...
js build. I am struggling to get a next build completing without the following error being thrown: > Build error occurred { ReferenceError:...
Read more >
Browser tdd: describe is not defined; bdd is ok - Google Groups
Weird situation: set up yeoman with backbone generator yo backbone with mocha.setup("bdd") the tests run with mocha.setup("tdd") getting ReferenceError: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found