NG 测试在控制台中显示名称

72G*_*2GM 16 karma-runner angular-cli angular

当存在相当普遍的错误(是的源映射是错误的)时,识别失败的测试可能会非常困难,如果我们可以显示测试名称而不是“已执行 27 of 172”,将会有很大帮助

在此处输入图片说明

类似于“执行 27 (TextActivityService Test) of 172

我在这里指的是所有测试都通过但控制台报告错误的时间。

这可能吗?

小智 8

您需要使用Karma Spec Reporter

用法:

  1. 要在您自己的 Node.js 项目中使用,只需执行

npm install karma-spec-reporter --save-dev

  1. 然后向记者添加“规范” karma.conf.js

// karma.conf.js

...
  config.set({
  ...
    reporters: ["spec"],
    specReporter: {
      maxLogLines: 5,         // limit number of lines logged per test
      suppressErrorSummary: true,  // do not print error summary
      suppressFailed: false,  // do not print information about failed tests
      suppressPassed: false,  // do not print information about passed tests
      suppressSkipped: true,  // do not print information about skipped tests
      showSpecTiming: false // print the time elapsed for each spec
    },
    plugins: ["karma-spec-reporter"],
  ...
Run Code Online (Sandbox Code Playgroud)


Sad*_*jee 0

当某些单元测试失败时,它会显示describe消息it作为测试用例名称。

例如:

describe('TestComponent', () => {
  it('should pass test', () => {
    expect(false).toBeTruthy();
  });
});
Run Code Online (Sandbox Code Playgroud)

TestComponent should pass test FAILED
Expected false to be truthy
然后,上述失败的单元测试将在控制台中显示。

  • 这就是我想避免的事情 (8认同)
  • 我的意思是当测试通过但在控制台中抛出错误时 (2认同)