【发布时间】:2019-05-07 22:38:13
【问题描述】:
我需要对用 NodeJS 编写的 rest api 进行单元测试。为此,我需要使用supertest npm 包。我关注 this tutorial article 来实现单元测试功能。
现在,本文提到mocha 本身已经包含在supertest 中,因此无需单独安装。所以,我只使用 - npm install --save-dev supertest 安装supertest。
但是,当我在我的package.json - "test": "mocha" 中添加这一行并运行npm test 时,它会给出错误提示'mocha' is not recognized as an internal or external command。我需要运行npm install --save-dev mocha 才能使其成功运行。但是为什么我需要单独包含mocha,如果这就是它应该运行的方式,为什么本文或supertest的npm主页上没有提到它?
【问题讨论】:
-
Mohit - 看看stackoverflow.com/questions/44219034/… 是否有帮助
-
谢谢@VimalMahi 我检查了这个线程,但不幸的是找不到我要找的东西。
标签: javascript node.js npm mocha.js supertest