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

时间:2018-12-31 11:56:36

标签: angular angular-cli karma-runner

如果存在相当普遍的错误(是,源映射为false),则很难识别失败的测试,如果我们能够显示测试名称而不是“执行172个中的27个”,将会非常有帮助。

enter image description here

类似“执行172次27(TextActivityService测试)

我指的是所有测试均通过但控制台报告错误。

这可能吗?

2 个答案:

答案 0 :(得分:0)

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

例如:

describe('TestComponent', () => {
  it('should pass test', () => {
    expect(false).toBeTruthy();
  });
});

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

答案 1 :(得分:0)

您需要使用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"],
  ...
相关问题