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

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

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

+7
javascript unit-testing karma-runner
source share
2 answers

Karma does a console.error capture (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.

+11
source share

You can write 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!") }); 
+3
source share

All Articles