Skip to content

Commit cbb7c9c

Browse files
committed
fix(log): no longer emitting 'undefined' for $log.info/err/etc in IE
Closes angular#1705
1 parent e2068ad commit cbb7c9c

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

src/ng/log.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function $LogProvider(){
151151
// we are IE which either doesn't have window.console => this is noop and we do nothing,
152152
// or we are IE where console.log doesn't have apply so we log at least first 2 args
153153
return function(arg1, arg2) {
154-
logFn(arg1, arg2);
154+
logFn(arg1, arg2 == null ? '' : arg2);
155155
}
156156
}
157157
}];

test/ng/logSpec.js

+37-15
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,23 @@ describe('$log', function() {
6969
}
7070
));
7171

72+
describe("IE logging behavior", function() {
73+
function removeApplyFunctionForIE() {
74+
log.apply = log.call =
75+
warn.apply = warn.call =
76+
info.apply = info.call =
77+
error.apply = error.call =
78+
debug.apply = debug.call = null;
7279

73-
it("should work in IE where console.error doesn't have apply method", inject(
74-
function() {
75-
log.apply = log.call =
76-
warn.apply = warn.call =
77-
info.apply = info.call =
78-
error.apply = error.call =
79-
debug.apply = debug.call = null;
80-
81-
$window.console = {log: log,
82-
warn: warn,
83-
info: info,
84-
error: error,
85-
debug: debug};
86-
},
80+
$window.console = {log: log,
81+
warn: warn,
82+
info: info,
83+
error: error,
84+
debug: debug};
85+
}
86+
87+
it("should work in IE where console.error doesn't have apply method", inject(
88+
removeApplyFunctionForIE,
8789
function($log) {
8890
$log.log.apply($log);
8991
$log.warn.apply($log);
@@ -92,7 +94,27 @@ describe('$log', function() {
9294
$log.debug.apply($log);
9395
expect(logger).toEqual('log;warn;info;error;debug;');
9496
})
95-
);
97+
);
98+
99+
it("should not attempt to log second argument in IE if it is not specified to prevent 'undefined' from being printed", inject(
100+
function() {
101+
log = function(arg1, arg2) { logger+= 'log;' + arg2; };
102+
warn = function(arg1, arg2) { logger+= 'warn;' + arg2; };
103+
info = function(arg1, arg2) { logger+= 'info;' + arg2; };
104+
error = function(arg1, arg2) { logger+= 'error;' + arg2; };
105+
debug = function(arg1, arg2) { logger+= 'debug;' + arg2; };
106+
},
107+
removeApplyFunctionForIE,
108+
function($log) {
109+
$log.log();
110+
$log.warn();
111+
$log.info();
112+
$log.error();
113+
$log.debug();
114+
expect(logger).toEqual('log;warn;info;error;debug;');
115+
})
116+
);
117+
});
96118

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

0 commit comments

Comments
 (0)