Categories
JavaScript Answers

How to install and run Mocha, the Node.js testing module?

Spread the love

To install and run Mocha, the Node.js testing module, we install the mocha package globally.

To install it, we run

npm install --global mocha

to install mocha globally.

We can also install it in the project folder as a dev dependency with

npm install --save-dev mocha

Then in package.json, we add

{
  //...
  "scripts": {
    "test": "mocha"
  }
  //...
}

to add the test script to run mocha installed in the node_modules folder.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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