Silence JavaScript console output
This is super helpful for unit testing with 100% code coverage, while maintaining a clean test output on the console!
First you need some basic setup code:
// Backup console.log so we can restore it later
var ___log = console.log;
/**
* Silences console.log
* Undo this effect by calling unmute().
*/
function mute() {
console.log = function(){};
}
/**
* Un-silences console.log
*/
function unmute() {
console.log = ___log;
}
Then, you can write code using mute() and unmute() like so:
mute();
MyClass.functionThatPrintsOutput();
unmute();Written by Shakeel Mohamed
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Console
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#