I am using VS Code. When I try to run the test in debug mode, it says describe is not a function. Thus, only way I am able to run the test is through npm Note.
Note: I am using mocha and chai.
var { describe,it, before, after } = require('mocha');
var assert = require('chai').assert;
var AuthAPI = require('../api/controllers/API.js');
describe('getItem tests', function() {
it('getItem ', function(done) {
var API = new AuthAPI(clientId, PASS, List);
api_jwt = API.getItem();
assert.isNotEmpty(api_jwt);
});
)}
I think you just need another launch configuration for your mocha tests.
Go to Debug section in your Visual Studio Code.
Click the select control, then select "Add Configuration..." (or just click the gear icon and then click the "Add Configuration..." button);
You should be able to select "Node.js: Mocha Tests" there, it would generate a launch config like that:
{
"type": "node",
"request": "launch",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/test"
],
"internalConsoleOptions": "openOnSessionStart"
},
describe
functions.Make sure your mocha tests are in ./test
folder and you have installed mocha locally or customise the launcher config.
Let's say you have a test ./test/it_should_work.js
(note, it does not have any require, since mocha binary knows that functions by itself)
describe('test', () => {
it('should work', () => {
});
})
Launch a newly created "Mocha Test" configuration, it should return a successful result.
test
✓ should work
1 passing (9ms)
But if you really need to programmatically launch mocha tests, check out this official wiki page https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With