mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
feature($exceptionHandler): $exceptionHandler now supports var_args
This commit is contained in:
parent
517811764d
commit
84823b2eff
4 changed files with 34 additions and 14 deletions
8
src/angular-mocks.js
vendored
8
src/angular-mocks.js
vendored
|
|
@ -249,8 +249,12 @@ angular.mock.$ExceptionHandlerProvider = function() {
|
|||
case 'log':
|
||||
var errors = [];
|
||||
handler = function(e) {
|
||||
errors.push(e);
|
||||
};
|
||||
if (arguments.length == 1) {
|
||||
errors.push(e);
|
||||
} else {
|
||||
errors.push([].slice.call(arguments, 0));
|
||||
}
|
||||
}
|
||||
handler.errors = errors;
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -10,13 +10,17 @@
|
|||
* The default implementation simply delegates to `$log.error` which logs it into
|
||||
* the browser console.
|
||||
*
|
||||
* In unit tests, if `angular-mocks.js` is loaded, this service is overriden by
|
||||
* In unit tests, if `angular-mocks.js` is loaded, this service is overridden by
|
||||
* {@link angular.module.ngMock.$exceptionHandler mock $exceptionHandler}
|
||||
*
|
||||
* @param {Error} exception Exception associated with the error.
|
||||
* @param {string=} cause optional information about the context in which
|
||||
* the error was thrown.
|
||||
*/
|
||||
function $ExceptionHandlerProvider(){
|
||||
function $ExceptionHandlerProvider() {
|
||||
this.$get = ['$log', function($log){
|
||||
return function(e) {
|
||||
$log.error(e);
|
||||
return function(exception, cause) {
|
||||
$log.error.apply($log, arguments);
|
||||
};
|
||||
}];
|
||||
}
|
||||
|
|
|
|||
3
test/angular-mocksSpec.js
vendored
3
test/angular-mocksSpec.js
vendored
|
|
@ -307,6 +307,9 @@ describe('ngMock', function() {
|
|||
var $exceptionHandler = $exceptionHandlerProvider.$get();
|
||||
$exceptionHandler('MyError');
|
||||
expect($exceptionHandler.errors).toEqual(['MyError']);
|
||||
|
||||
$exceptionHandler('MyError', 'comment');
|
||||
expect($exceptionHandler.errors[1]).toEqual(['MyError', 'comment']);
|
||||
}));
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,24 @@
|
|||
'use strict';
|
||||
|
||||
describe('$exceptionHandler', function() {
|
||||
it('should log errors with single argument', function() {
|
||||
module(function($provide){
|
||||
$provide.service('$exceptionHandler', $ExceptionHandlerProvider);
|
||||
});
|
||||
inject(function($log, $exceptionHandler) {
|
||||
$exceptionHandler('myError');
|
||||
expect($log.error.logs.shift()).toEqual(['myError']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should log errors', function() {
|
||||
module(function($provide){
|
||||
$provide.service('$exceptionHandler', $ExceptionHandlerProvider);
|
||||
it('should log errors with multiple arguments', function() {
|
||||
module(function($provide){
|
||||
$provide.service('$exceptionHandler', $ExceptionHandlerProvider);
|
||||
});
|
||||
inject(function($log, $exceptionHandler) {
|
||||
$exceptionHandler('myError', 'comment');
|
||||
expect($log.error.logs.shift()).toEqual(['myError', 'comment']);
|
||||
});
|
||||
});
|
||||
inject(function($log, $exceptionHandler) {
|
||||
$exceptionHandler('myError');
|
||||
expect($log.error.logs.shift()).toEqual(['myError']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue