From e7c20e049439db558c76c8c75708b32b576baf24 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 29 Jun 2011 21:42:39 -0400 Subject: [PATCH] Ensure we don't throw errors for warning handler tests if console is not defined --- test/test-warn-handlers.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/test/test-warn-handlers.js b/test/test-warn-handlers.js index e729cba..6c875b0 100644 --- a/test/test-warn-handlers.js +++ b/test/test-warn-handlers.js @@ -31,6 +31,23 @@ var common = require( './common' ), ; +/** + * Return the console object, without throwing errors if it does not exist + * + * @return {Object} console + */ +function backupConsole() +{ + // ensure that we don't throw errors if console is not defined + if ( typeof console !== 'undefined' ) + { + return console; + } + + return undefined; +} + + /** * The log warning handler should log warnings to the console */ @@ -39,7 +56,7 @@ var common = require( './common' ), var logged = false, // back up console ref - console_ = console + console_ = backupConsole() ; // mock console @@ -74,7 +91,7 @@ var common = require( './common' ), ( function testLogWarningHandlerHandlesMissingConsole() { // back up console - var console_ = console; + var console_ = backupConsole(); // destroy it console = undefined; @@ -95,7 +112,7 @@ var common = require( './common' ), ( function testLogWarningHandlerWillFallBackToLogMethodIfWarnIsMissing() { // back up and overwrite console to contain only log() - var console_ = console, + var console_ = backupConsole(), given = ''; console = { @@ -149,7 +166,7 @@ var common = require( './common' ), ( function testDismissWarningHandlerShouldDoNothing() { // destroy the console to ensure nothing is logged - var console_ = console; + var console_ = backupConsole(); console = undefined; // don't catch anything, to ensure no errors occur and that no exceptions