Skip to content

Commit

Permalink
fix(log): prevent logging undefined for $log in IE
Browse files Browse the repository at this point in the history
  • Loading branch information
colincasey authored and jamesdaily committed Jan 27, 2014
1 parent 9771587 commit 6e79d86
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/ng/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function $LogProvider(){
// we are IE which either doesn't have window.console => this is noop and we do nothing,
// or we are IE where console.log doesn't have apply so we log at least first 2 args
return function(arg1, arg2) {
logFn(arg1, arg2);
logFn(arg1, arg2 == null ? '' : arg2);
}
}
}];
Expand Down
60 changes: 41 additions & 19 deletions test/ng/logSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,23 @@ describe('$log', function() {
}
));

describe("IE logging behavior", function() {
function removeApplyFunctionForIE() {
log.apply = log.call =
warn.apply = warn.call =
info.apply = info.call =
error.apply = error.call =
debug.apply = debug.call = null;

it("should work in IE where console.error doesn't have apply method", inject(
function() {
log.apply = log.call =
warn.apply = warn.call =
info.apply = info.call =
error.apply = error.call =
debug.apply = debug.call = null;

$window.console = {log: log,
warn: warn,
info: info,
error: error,
debug: debug};
},
$window.console = {log: log,
warn: warn,
info: info,
error: error,
debug: debug};
}

it("should work in IE where console.error doesn't have an apply method", inject(
removeApplyFunctionForIE,
function($log) {
$log.log.apply($log);
$log.warn.apply($log);
Expand All @@ -92,20 +94,40 @@ describe('$log', function() {
$log.debug.apply($log);
expect(logger).toEqual('log;warn;info;error;debug;');
})
);
);

it("should not attempt to log the second argument in IE if it is not specified", inject(
function() {
log = function(arg1, arg2) { logger+= 'log;' + arg2; };
warn = function(arg1, arg2) { logger+= 'warn;' + arg2; };
info = function(arg1, arg2) { logger+= 'info;' + arg2; };
error = function(arg1, arg2) { logger+= 'error;' + arg2; };
debug = function(arg1, arg2) { logger+= 'debug;' + arg2; };
},
removeApplyFunctionForIE,
function($log) {
$log.log();
$log.warn();
$log.info();
$log.error();
$log.debug();
expect(logger).toEqual('log;warn;info;error;debug;');
})
);
});

describe("$log.debug", function () {

beforeEach(initService(false));

it("should skip debugging output if disabled", inject(
function(){
$window.console = {log: log,
warn: warn,
info: info,
error: error,
debug: debug};
},
},
function($log) {
$log.log();
$log.warn();
Expand All @@ -115,7 +137,7 @@ describe('$log', function() {
expect(logger).toEqual('log;warn;info;error;');
}
));

});

describe('$log.error', function() {
Expand Down

0 comments on commit 6e79d86

Please sign in to comment.