最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - 'mocha' is not recognized as an internal or external command - mocha not getting automatically inst

programmeradmin8浏览0评论

I need to unit-test my rest api written in NodeJS. For this, I need to use supertest npm package. I was following this tutorial article for implementing the unit test functionality.

Now, in this article it is mentioned that mocha is already included in supertest itself, so there's no need to install it separately. So, I only install supertest using - npm install --save-dev supertest.

But, when I add this line in my package.json - "test": "mocha", and run npm test, it gives error saying 'mocha' is not recognized as an internal or external mand. I need to run npm install --save-dev mocha to make it run successfully. But why do I need to include mocha separately and if that's how it is supposed to run, why is it not mentioned in this article or on npm homepage of supertest?

I need to unit-test my rest api written in NodeJS. For this, I need to use supertest npm package. I was following this tutorial article for implementing the unit test functionality.

Now, in this article it is mentioned that mocha is already included in supertest itself, so there's no need to install it separately. So, I only install supertest using - npm install --save-dev supertest.

But, when I add this line in my package.json - "test": "mocha", and run npm test, it gives error saying 'mocha' is not recognized as an internal or external mand. I need to run npm install --save-dev mocha to make it run successfully. But why do I need to include mocha separately and if that's how it is supposed to run, why is it not mentioned in this article or on npm homepage of supertest?

Share Improve this question asked Dec 6, 2018 at 9:08 Mohit BhardwajMohit Bhardwaj 10.1k7 gold badges40 silver badges65 bronze badges 2
  • 1 Mohit - See if stackoverflow./questions/44219034/… helps – Vimal Maheedharan Commented Dec 6, 2018 at 9:32
  • Thanks @VimalMahi I checked this thread but unfortunately couldn't find exactly what I'm looking for. – Mohit Bhardwaj Commented Dec 6, 2018 at 11:18
Add a ment  | 

1 Answer 1

Reset to default 4

I went to Supertest page on npmjs and checked the dependencies. Mocha is listed as a dev dependency. it means Mocha was used while creating supertest, but is not required for supertest to function. When I work on Node.js project, I install certain packages as dev dependencies. These could be packages for testing (Mocha) or linting (Standard). What it means is when the project is deployed, it will not need these packages to function.

Also, you can use npm list mand to see which modules are installed. I just installed supertest and ran npm list. This is structure of supertest :

As you can see Mocha is not listed

Further, ran npm ls mocha and output is: $ npm ls mocha [email protected] E:\Nodetest -- (empty)

and when I ran npm ls supertest, output is: $ npm ls supertest [email protected] E:\Nodetest -- [email protected]

Why sis the article say mocha is available? may be in an earlier version of supertest it was included as a dependency

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论