Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(log): no longer emitting 'undefined' for $log.info/err/etc in IE #4088

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
52 changes: 37 additions & 15 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 apply method", inject(
removeApplyFunctionForIE,
function($log) {
$log.log.apply($log);
$log.warn.apply($log);
Expand All @@ -92,7 +94,27 @@ describe('$log', function() {
$log.debug.apply($log);
expect(logger).toEqual('log;warn;info;error;debug;');
})
);
);

it("should not attempt to log second argument in IE if it is not specified to prevent 'undefined' from being printed", 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 () {

Expand Down