Introduction
Mocha is one of the most important frameworks of Javascript for Node development. It is generally used for asynchronous testing and is compatible with all of the major libraries of Node, including
- should.js
- express.js
- better-assert
We can install the mocha framework using the npm install command,
npm install -g mochaTesting Synchronous Code
Synchronous Coding means running one line of code at a time. The code is executed one line at a time in the order that the codes appear.
In Mocha, while Synchronous Coding, we omit callbacks to inform the compiler to continue to the next test case.
Let us look at an example to understand Synchronous Coding.
arrow.js
var assert = require('assert');
describe('arr', function () {
describe('#indexOf()', function () {
it('should return -1 when the value is not present in the array', function () {
assert.equal([1, 2, 3].indexOf(4), -1);
});
it('should return 0 when the value is not present in the array', function () {
assert.equal([1, 2, 3].indexOf(1), 0);
});
});
});

In the above code, we run two test cases using Mocha. If the value is not present in the array, we return -1, and in the second test case, if the value is present, we return 0.




