Reputation: 80395
I'm unit testing a function which contains a console.log()
call.
How can I prevent the output of that call from being displayed in the output console of my test runner, in this case, Karma.
I'm using Jasmine.
I'm looking for a more elegant way than overriding browser's console
methods, preferably a config.
Upvotes: 8
Views: 5562
Reputation: 185
The problem with the accepted answer is that it also suppress Karma logs.
If you only want to suppress the logging for the called methods set browserConsoleLogOptions.level
to an appropriate level in your karma.conf.js
. Setting browserConsoleLogOptions.level
to "warn"
will suppress all the log
and debug
logs.
copy-paste-ready snippet:
// file: karma.conf.js
module.exports = function (config) {
config.set({
// other options...
browserConsoleLogOptions: {level: "warn"}
}
}
See the karma configuration file documentation for references.
Upvotes: 6
Reputation: 226
Set client.captureConsole = false
in your karma.conf.js
config set function.
module.exports = function (config) {
config.set({
client: {
captureConsole: false
}
});
};
Original feature request.
Upvotes: 18