Skip to content

Instantly share code, notes, and snippets.

@jboxman
Last active June 25, 2017 12:57
Show Gist options
  • Save jboxman/1f2d1e0c4818d7dfd087a14fd5a4c41c to your computer and use it in GitHub Desktop.
Save jboxman/1f2d1e0c4818d7dfd087a14fd5a4c41c to your computer and use it in GitHub Desktop.
silence console.log for a Promise in a test
function *silentLog(p) {
function restoreLog() {return console.log = logg, undefined;}
const logg = console.log;
console.log = function() {}
const [fulfill, reject] = yield;
p().then(fulfill, reject).then(restoreLog, restoreLog);
}
function withSilentLog(youPromised, handleFulfill = function() {}, handleReject = function() {}) {
const it = silentLog(youPromised);
it.next();
it.next([handleFulfill, handleReject]);
}
// Lots of work just to accomplish this!
withSilentLog(() => getAllOpinions('discussion_id'), null, fn);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment