admin管理员组文章数量:1400038
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
?
- 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
1 Answer
Reset to default 4I 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
本文标签:
版权声明:本文标题:javascript - 'mocha' is not recognized as an internal or external command - mocha not getting automatically inst 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744233855a2596465.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论