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

I need to unit-test my rest api written in NodeJS. For this, I need to use supertest npm package. I was

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744233855a4564381.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信