Mocha未显示测试用例的数量

问题描述 投票:0回答:1

我在测试用例中使用的是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.js mocha chai supertest nyc
1个回答
0
投票

似乎您将错误的摩卡报告程序设置为htmltexthtml报告程序不适用于控制台,并且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

希望有帮助

© www.soinside.com 2019 - 2024. All rights reserved.