Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture console.error with Karma unit test runner?

Karma will capture any messages written to console.log but not anything written to console.error. I understand that karma uses log4js under the hood.

Is there any way to configure karma to capture console.error?

like image 259
daw Avatar asked Dec 06 '13 18:12

daw


2 Answers

Karma does capture console.error (see https://github.com/karma-runner/karma/blob/415d0257c23ff7be07e240648bfff0bdefa9b0b6/client/karma.js#L70)

Make sure you set config client.captureConsole: true and use the latest Karma.

like image 93
Vojta Avatar answered Nov 05 '22 22:11

Vojta


You could capture the console.error as described in this blog post

describe('TestSuite', function() {
  var oldError = console.error;
  beforeEach(function() {
    console.error = function(message) {
      throw new Error(message);
    };
  });
  return afterEach(function() {
    return console.error = oldError;
  });

  it('should fail', function() {
    console.error("Oops!")
  });
like image 5
Carlos Morales Avatar answered Nov 05 '22 23:11

Carlos Morales