Introduction
In javascript language, a double-callback is a callback that we anticipate to be called once but gets called twice or more times for whatever reason. To test those we basically uses the mocha known to be testing double callbacks.
This article will go through the sequence in which Mocha's components are executed. It's worth noting that all hooks, describe, and callbacks will be executed in the order you specify. That is, precisely as they appear in your test file.
Getting Started
Before getting started with writing our test for double callbacks go ahead with the necessary setup needed for the article mentioned below. Run the basic command such as yarn init or npm init. To initialise the project with package manager of your choice.
package.json
Note that if you don’t specify the test script as mentioned below then you have call it through the .node_modules folder by specifying the path of mocha.test.js
{
"name": "aync-mocha-test",
"version": "1.0.0",
"main": "index.js",
"author": "aman-thakur",
"license": "MIT",
"dependencies": {
"axios": "^0.26.0"
},
"scripts": {
"test": "mocha index.js"
},
"devDependencies": {
"mocha": "^9.2.1"
}
}
Test Program
// create file index.js
const assert = require("assert");
it("double codingninjas", (codingninjas) => {
setImmediate(codingninjas);
setImmediate(codingninjas);
});Output

Run the command given below
If you are using npm:
npm test
Or, if you are using yarn:
yarn test





