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

Commit 84823b2

Browse files
committed
feature($exceptionHandler): $exceptionHandler now supports var_args
1 parent 5178117 commit 84823b2

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

src/angular-mocks.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,12 @@ angular.mock.$ExceptionHandlerProvider = function() {
249249
case 'log':
250250
var errors = [];
251251
handler = function(e) {
252-
errors.push(e);
253-
};
252+
if (arguments.length == 1) {
253+
errors.push(e);
254+
} else {
255+
errors.push([].slice.call(arguments, 0));
256+
}
257+
}
254258
handler.errors = errors;
255259
break;
256260
default:

src/service/exceptionHandler.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010
* The default implementation simply delegates to `$log.error` which logs it into
1111
* the browser console.
1212
*
13-
* In unit tests, if `angular-mocks.js` is loaded, this service is overriden by
13+
* In unit tests, if `angular-mocks.js` is loaded, this service is overridden by
1414
* {@link angular.module.ngMock.$exceptionHandler mock $exceptionHandler}
15+
*
16+
* @param {Error} exception Exception associated with the error.
17+
* @param {string=} cause optional information about the context in which
18+
* the error was thrown.
1519
*/
16-
function $ExceptionHandlerProvider(){
20+
function $ExceptionHandlerProvider() {
1721
this.$get = ['$log', function($log){
18-
return function(e) {
19-
$log.error(e);
22+
return function(exception, cause) {
23+
$log.error.apply($log, arguments);
2024
};
2125
}];
2226
}

test/angular-mocksSpec.js

+3
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ describe('ngMock', function() {
307307
var $exceptionHandler = $exceptionHandlerProvider.$get();
308308
$exceptionHandler('MyError');
309309
expect($exceptionHandler.errors).toEqual(['MyError']);
310+
311+
$exceptionHandler('MyError', 'comment');
312+
expect($exceptionHandler.errors[1]).toEqual(['MyError', 'comment']);
310313
}));
311314

312315

test/service/exceptionHandlerSpec.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
'use strict';
22

33
describe('$exceptionHandler', function() {
4+
it('should log errors with single argument', function() {
5+
module(function($provide){
6+
$provide.service('$exceptionHandler', $ExceptionHandlerProvider);
7+
});
8+
inject(function($log, $exceptionHandler) {
9+
$exceptionHandler('myError');
10+
expect($log.error.logs.shift()).toEqual(['myError']);
11+
});
12+
});
413

514

6-
it('should log errors', function() {
7-
module(function($provide){
8-
$provide.service('$exceptionHandler', $ExceptionHandlerProvider);
9-
});
10-
inject(function($log, $exceptionHandler) {
11-
$exceptionHandler('myError');
12-
expect($log.error.logs.shift()).toEqual(['myError']);
15+
it('should log errors with multiple arguments', function() {
16+
module(function($provide){
17+
$provide.service('$exceptionHandler', $ExceptionHandlerProvider);
18+
});
19+
inject(function($log, $exceptionHandler) {
20+
$exceptionHandler('myError', 'comment');
21+
expect($log.error.logs.shift()).toEqual(['myError', 'comment']);
22+
});
1323
});
14-
});
1524
});

0 commit comments

Comments
 (0)