node.js - 摩卡没有显示测试用例的数量
问题描述
我在我的测试用例中使用 mocha、chai、supertest 和 nyc。我所有的测试用例都按预期工作。但是我最后看不到测试用例的总数。
21 passing (150ms) // <--- these counts are missing in console
1 failing (150ms) // <--- these counts are missing in console
我无法看到有多少测试用例通过(或失败)。它只是执行它们并退出该过程。
这就是我的测试用例的结构:
describe("GET /", () => {
it("should return all users", async () => {
await model.insertMany(users);
const res = await request(app).get("/users");
expect(res.status).to.equal(200);
expect(res.body.data.length).to.equal(2);
});
});
这就是它的运行方式:使用npm test
:
"scripts": {
"start": "node index.js",
"test": "NODE_ENV=test nyc --reporter=html --reporter=text mocha --exit --timeout 15000"
}
版本:
node - v11.15.0
npm - 6.7.0
mocha - 6.2.1
chai - 4.2.0
nyc - 14.1.1
supertest - 4.0.2
任何线索将不胜感激:)
解决方案
似乎您将错误的 mocha 记者设置为html
and text
。html
记者不适合控制台,text
记者不存在。参考:https ://mochajs.org/#reporters
解决方法是删除--reporter=xxx
然后 Mocha 将使用默认spec
报告器,例如
"test": "NODE_ENV=test nyc mocha --exit --timeout 15000"
如果你一直坚持使用多记者,你可以使用这个库https://www.npmjs.com/package/mocha-multi-reporters
希望能帮助到你
推荐阅读
- javascript - JS按对象字段拆分对象数组
- python - 如何在 pythonanywhere 上部署 Flask 应用程序,并将文件夹作为模块
- javascript - 将 onprogress 侦听器附加到 XMLHttpRequest.upload 会停止发送 POST 数据(wtf?)
- c# - dotnet core authorize 始终重定向到身份默认登录页面
- html - 如何让我的资产净值在右上角对齐?
- javascript - 如何在 HOC 中使用计算属性名称?
- python - 没有重复的 DataFrame 的最小值
- html - 如何为 Web HTML 导出 Godot 场景?
- ksh - 字符串捕获并打印下一个字符。
- hyperledger-fabric - 为什么我们需要在 Hyperledger Fabric 的开发中使用 Solo,在生产中使用 Kafka?