Webstorm throws an error for mocha describe function

I have a very simple code to create a mocha test. But It doesn't give any warning that it doesn't recognize 'describe', but when I run the test it throws error saying "TypeError: describe is not a function". Interestingly, yesterday all my test cases were running, and nothing has changed since then. This morning I just opened webstorm, ran the tests and getting this error.

I've tried to look for answers online but haven't really found an answer yet.

Here is my code:

console.log('msg');
const { describe, it } = require('mocha');

console.log('msg2');
console.log(typeof describe);

describe('virtualagents', () => {
console.log('desc');

it('runs as expected', (done) => {
done();
});
});
0
2 comments
Avatar
Permanently deleted user

I just tried to run the mocha test from terminal, and it throws the same error there. So it isn't a Webstorm issue.

So I'll keep looking online for a solution but if anybody knows the answer already, please comment.

0

you must be running it as a standalone node.js app (node myTest.js) rather then using mocha to run it... This is not supposed to work, please make sure to run it with mocha test runner...

In WebStorm, make sure to use Mocha run configuration; in terminal, use mocha --ui bdd mytest.js

0

Please sign in to leave a comment.