首页 > 解决方案 > 摩卡没有显示测试用例的数量

问题描述

我在我的测试用例中使用 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

任何线索将不胜感激:)

标签: node.jsmocha.jschaisupertestnyc

解决方案


似乎您将错误的 mocha 记者设置为htmland texthtml记者不适合控制台,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

希望能帮助到你


推荐阅读