Mochajs

Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases.

Some of the features of mocha are as follow:

  • simple async support, including promises.
    async test timeout support.
    before, after, before each, after each hooks (very useful to clean the environment where each test!).
    test coverage reporting.

1)Installing mocha with npm globally in terminal

npm install –global mocha

2)Making directory

mkdir test

3)Knowing version of mocha

which mocha

4)Creating package.json file

“scripts”: {
“test”: “mocha”
}

5)Run test with;

npm test

6)Creating addition.js file in test folder

‘use strict’;

var assert=require(“assert”);
describe(‘addition’, function () {
it(‘should add 5+6 correctly’, function (done) {

var a = 5 + 6;
assert(a===11);
done();
});
});

7)Running addition.js in terminal

mocha test/addition.js //test folder

8)Using reporter in browser

npm install –save-dev mochawesome
mocha test/addition.js –reporter mochawesome

9)Using different reporter

mocha test/addition.js –reporter progress
mocha test/addition.js –reporter nyan


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us


Recent Post


  • The Role of IT Service Companies in Business Innovation

    In today’s dynamic corporate environment, information technology (IT) has emerged as a vital engine of innovation and growth. IT service providers are crucial in helping with the shift as organizations work to remain competitive and fulfill digital world demands. The relevance of information technology in organizations and the crucial help offered by IT service companies […]

  • How To Build a Caching System Through Redis in Node JS?

    In today’s world, you don’t want your application to be slow. If a website is taking too long to respond there might be a chance the user will not visit your application again and Boosting node js application. In this article, we are going to implement the caching system through Redis in NodeJS. But before […]

  • Revolutionizing Healthcare with Big Data: 5 Impactful Use Cases

    In this blog, we are going to understand Big Data and how it is going to revolutionize the healthcare industry. So, first, let’s know what big data is. So, big data is the large volume of data that is coming from businesses, organizations, and people at a very high speed. Big data contains a variety […]

  • The Rise of No-Code/Low-Code Platforms: Democratizing Software Development

    As we are witnessing a paradigm shift in technology, the way we develop software is also undergoing a significant transformation. Just imagine a world where you can design and develop software applications just as easily as you organize your wardrobe. This is what no-code/low-code platform promises, These platforms offer visual tools and seamless interfaces that […]

  • NLP: A Human Way To Talk With Computers

    In a world where dependency on technology is increasing day by day, our interaction with computers and machines has evolved drastically. It is seen very normally that the humans are talking to the computers in their own language and getting their work done. But haven’t we been taught that computers only understand machine language? Well, […]

  • How Quantum Computing is Transforming Software Development Progress?

    Hello there! In this blog, I’ll outline how quantum computing can be combined with software development to rethink how we have been creating programs up to this point and how it will completely change the software development progress and you’re going to know how quantum computing helps software development progress. But before I discuss how […]