How do you install and run Mocha, the Node.js testing module? Getting “mocha: command not found” after install

前端 未结 5 969
暖寄归人
暖寄归人 2020-12-07 11:40

I\'m having trouble getting Mocha to work as expected, and I\'d love to say as documented, but there (appears) to not be much documentation on actually getting the thing run

5条回答
  •  遥遥无期
    2020-12-07 12:14

    To run Mocha with mocha command from your terminal you need to install mocha globally on this machine:

    npm install --global mocha
    

    Then cd to your projectFolder/test and run mocha yourTestFileName.js


    If you want to make mocha available inside your package.json as a development dependency:

    npm install --save-dev mocha
    

    Then add mocha to your scripts inside package.json.

    "scripts": {
        "test": "mocha"
      },
    

    Then run npm test inside your terminal.

提交回复
热议问题