πŸŽ“  Graduation show details here: April 26, 2025  πŸŽ‰
menu

πŸŽ“  Graduation show details here: April 26, 2025  πŸŽ‰
Shakeel Mohamed wordmark logo set in the Mindful Roman typeface which he designed

Graphic Designer: Branding, typography, leadership

publicWork swap_callsExperiments

About


2015-09-04

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();


Instagram
LinkedIn