Ensure we don't throw errors for warning handler tests if console is not defined
parent
f405f072f2
commit
e7c20e0494
|
@ -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
|
* The log warning handler should log warnings to the console
|
||||||
*/
|
*/
|
||||||
|
@ -39,7 +56,7 @@ var common = require( './common' ),
|
||||||
var logged = false,
|
var logged = false,
|
||||||
|
|
||||||
// back up console ref
|
// back up console ref
|
||||||
console_ = console
|
console_ = backupConsole()
|
||||||
;
|
;
|
||||||
|
|
||||||
// mock console
|
// mock console
|
||||||
|
@ -74,7 +91,7 @@ var common = require( './common' ),
|
||||||
( function testLogWarningHandlerHandlesMissingConsole()
|
( function testLogWarningHandlerHandlesMissingConsole()
|
||||||
{
|
{
|
||||||
// back up console
|
// back up console
|
||||||
var console_ = console;
|
var console_ = backupConsole();
|
||||||
|
|
||||||
// destroy it
|
// destroy it
|
||||||
console = undefined;
|
console = undefined;
|
||||||
|
@ -95,7 +112,7 @@ var common = require( './common' ),
|
||||||
( function testLogWarningHandlerWillFallBackToLogMethodIfWarnIsMissing()
|
( function testLogWarningHandlerWillFallBackToLogMethodIfWarnIsMissing()
|
||||||
{
|
{
|
||||||
// back up and overwrite console to contain only log()
|
// back up and overwrite console to contain only log()
|
||||||
var console_ = console,
|
var console_ = backupConsole(),
|
||||||
given = '';
|
given = '';
|
||||||
|
|
||||||
console = {
|
console = {
|
||||||
|
@ -149,7 +166,7 @@ var common = require( './common' ),
|
||||||
( function testDismissWarningHandlerShouldDoNothing()
|
( function testDismissWarningHandlerShouldDoNothing()
|
||||||
{
|
{
|
||||||
// destroy the console to ensure nothing is logged
|
// destroy the console to ensure nothing is logged
|
||||||
var console_ = console;
|
var console_ = backupConsole();
|
||||||
console = undefined;
|
console = undefined;
|
||||||
|
|
||||||
// don't catch anything, to ensure no errors occur and that no exceptions
|
// don't catch anything, to ensure no errors occur and that no exceptions
|
||||||
|
|
Loading…
Reference in New Issue