Introduction
In a software development life cycle, testing has a significant role as it helps build a viable error-free application and has a high performance. This blog discusses a famous framework that allows simplifying testing in a node-based application. Mocha is a feature-packed JavaScript test framework that can be used with Angular, Vue, Express, etc.
Mocha allows performing asynchronous testing simple.
Delaying Tests
Before a suite is run, such as a dynamically generated test, it is possible that we need to perform an asynchronous operation. To do this, we need to delay the root suite by running Mocha with a -delay flag. The delay tag attaches a callback function run() to the global context.
setTimeout(function() {
// perform something
describe('personal suite', function() {
// ...
});
run();
}, 2500);
An example that does not use setTimeout
const assert = require('assert');
const fn = async x => {
return new Promise(resolve => {
setTimeout(resolve, 5000, 4 * x);
});
};
(async function () {
const z = await fn(3);
describe('personal suite', function () {
it(`Value ${z}`, function () {
assert.strictEqual(z, 6);
});
});
run();
})();




