27

It can be quite difficult to identify a failing test when there is a fairly generic error (yes source maps is false) and would help greatly if we could show the test name instead of "executed 27 of 172"

enter image description here

Something like "executed 27 (TextActivityService Test) of 172

I'm referring here to when all tests pass but the console is reporting errors.

Is this possible?

72GM
  • 2,926
  • 3
  • 27
  • 33
  • 13
    don't you just love the people that downvote but aren't big enough to add a comment... this is a perfectly reasonable question and if you'd been in this situation you'd understand why – 72GM Jan 07 '19 at 08:16
  • 1
    I am in this situation years later. Does anyone has a solution for this? Like the logs to show the spec file that was executed. This is really a problem in case of an ERROR. – James Ikubi Mar 16 '21 at 13:26

2 Answers2

14

You need to use Karma Spec Reporter.

Usage:

  1. To use in your own Node.js project, just execute

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

  1. Then add 'spec' to reporters in 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"],
  ...
Community
  • 1
  • 1
Valdas G
  • 166
  • 1
  • 6
0

When some unit test fails, it shows describe and it message as test case name.

For example:

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

Then, the above failed unit test will be shown as TestComponent should pass test FAILED
Expected false to be truthy
in the console.

Saddam Pojee
  • 1,518
  • 9
  • 14