Last active
June 25, 2017 12:57
-
-
Save jboxman/1f2d1e0c4818d7dfd087a14fd5a4c41c to your computer and use it in GitHub Desktop.
silence console.log for a Promise in a test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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