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

Commit 4ff1a65

Browse files
colincaseybtford
authored andcommitted
fix(log): prevent logging undefined for $log in IE
Closes #1705
1 parent 21527db commit 4ff1a65

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
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

+41-19
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 an apply method", inject(
88+
removeApplyFunctionForIE,
8789
function($log) {
8890
$log.log.apply($log);
8991
$log.warn.apply($log);
@@ -92,20 +94,40 @@ 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 the second argument in IE if it is not specified", 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 () {
98-
120+
99121
beforeEach(initService(false));
100-
122+
101123
it("should skip debugging output if disabled", inject(
102124
function(){
103125
$window.console = {log: log,
104126
warn: warn,
105127
info: info,
106128
error: error,
107129
debug: debug};
108-
},
130+
},
109131
function($log) {
110132
$log.log();
111133
$log.warn();
@@ -115,7 +137,7 @@ describe('$log', function() {
115137
expect(logger).toEqual('log;warn;info;error;');
116138
}
117139
));
118-
140+
119141
});
120142

121143
describe('$log.error', function() {

0 commit comments

Comments
 (0)