How can I retrieve the current test’s name within a Mocha test?

If you are directly inside a callback to describe, you can use this.title for the title of the describe or this.fullTitle() to get the hierarchical title of the describe (ancestors’ titles + the title of this one). If you are inside a callback to it you can use this.test.title or this.test.fullTitle() respectively. So: describe(“top”, function() … Read more

global leak errors in mocha

Yes, Mocha features a global leak detection mechanism which alerts and fails if your code under test introduces global variables. If hasCert is declared in a library and you have no control over its creation, you can tell Mocha to ignore it. On the command line, $ mocha –globals hasCert To quote the documentation: [This … Read more

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”: … Read more

Running Mocha setup before each suite rather than before each test

There’s no call similar to beforeEach or before that does what you want. But it is not needed because you can do it this way: function makeSuite(name, tests) { describe(name, function () { before(function () { console.log(“shared before”); }); tests(); after(function () { console.log(“shared after”); }); }); } makeSuite(‘Suite one’, function(){ it(‘S1 Test one’, function(done){ … Read more

Difference between fake, spy, stub and mock of sinon library ( sinon fake vs spy vs stub vs mock )

Just for understanding purpose call: FuncInfoCollector = is a Function that records arguments, return value, the value of this(context) and exception thrown (if any) for all of its calls. (this FuncInfoCollector is dummy name given by me, it is not present in SINON lib) Fake = FuncInfoCollector + can only create a fake function. To … Read more

How to mock request and response in nodejs to test middleware/controllers?

There’s a semi decent implementation at node-mocks-http Require it: var mocks = require(‘node-mocks-http’); you can then compose req and response objects: req = mocks.createRequest(); res = mocks.createResponse(); You can then test your controller directly: var demoController = require(‘demoController’); demoController.login(req, res); assert.equal(res.json, {}) caveat There is at time of writing an issue in this implementation to … Read more

mocha Error: No test files found: “test/” npm ERR! Test failed

seeing your project structure, seems that you have one test.js so mocha should target this file. “scripts”: { “test”: “mocha test.js –reporter mocha-junit-reporter –timeout 60000 –exit”, }, If you want to add more test files, it is better to put them inside test directory e.g. /test and must change the target to test files inside … Read more

TypeScript error TS2403: Subsequent variable declarations must have the same type

I added the following property to the tsconfig file “compilerOptions”: { “skipLibCheck”: true }, This tells TypeScript that we want to skip the type checking of libraries in the node_modules folder. This saves compilation time and stops conflicting types in node modules from breaking the build. For those who want some explanation on why you … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)