X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2FUtil.js;h=3b8c1b8d64f6b2fa8ad3d0e83faedd605794f9d1;hb=1b7afc93886e2927b6f320e8e1ed4dd6bd9ab53b;hp=8937e43920a270718485010ceab02395e4326afc;hpb=65129ba82d4efe12714be88fa3c792149c00ca10;p=dygraphs.git diff --git a/auto_tests/tests/Util.js b/auto_tests/tests/Util.js index 8937e43..3b8c1b8 100644 --- a/auto_tests/tests/Util.js +++ b/auto_tests/tests/Util.js @@ -147,3 +147,24 @@ Util.overrideXMLHttpRequest = function(data) { Util.formatDate = function(dateMillis) { return Dygraph.dateString_(dateMillis).slice(0, 10); // 10 == "YYYY/MM/DD".length }; + +/** + * Capture console.{log,warn,error} statements into obj. + * obj will look like {log:[], warn:[], error:[]} + * This returns a function which will restore the original console. + */ +Util.captureConsole = function(obj) { + obj.log = []; + obj.warn = []; + obj.error = []; + var orig = [console.log, console.warn, console.error]; + console.log = function(text) { obj.log.push(text); }; + console.warn = function(text) { obj.warn.push(text); }; + console.error = function(text) { obj.error.push(text); }; + + return function() { + console.log = orig[0]; + console.warn = orig[1]; + console.error = orig[2]; + }; +};