unit test mocha Visual Studio Code describe is not defined
Finally!!! After a long search and reading some tutorials and comments I found the solution: the problem was with the config.
Open the test config file and delete the following lines:
"-u", <<<< delete this line
"tdd", <<<< delete this line
launch.js
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"--require",
"ts-node/register",
"-u", <<<< delete this line
"tdd", <<<< delete this line
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/tests/**/*.spec.ts"
],
"internalConsoleOptions": "openOnSessionStart"
},
Run the test again and it will work.
I've stumbled upon mocha docs here:
Interfaces and UI Switch
TLDR;
--ui, -u
switch has two options: bdd
and tdd
. However, it also states it will be defaulted to bdd
when --ui, -u
switch is not supplied.
Hence, when you're using --ui tdd
switch, you're expected to use TDD interface which provides suite(), test(), suiteSetup(), suiteTeardown(), setup(), and teardown()
compared to BDD's describe(), context(), it(), specify(), before(), after(), beforeEach(), and afterEach()
approach.
That explains why it screams describe
function is not defined.