diff options
| author | Fred Sauer | 2013-01-16 18:01:03 -0800 |
|---|---|---|
| committer | Misko Hevery | 2013-01-17 23:11:02 -0800 |
| commit | 1f8be1ca66b312fdc396403f01ee8aae9371577a (patch) | |
| tree | 275faae81a6b38bc844e1b63515a4b3786a4934e /src/ngMock/angular-mocks.js | |
| parent | cbc2024092b326cc7e46d4defc4bf2248bbeb835 (diff) | |
| download | angular.js-1f8be1ca66b312fdc396403f01ee8aae9371577a.tar.bz2 | |
docs(exceptionHandler): document testing
Update src/ng/exceptionHandler.js
Here's an iniitla attempt at documenting how one might write a
test using $exceptionHandlerProvider. The key take-away is the use
of this pattern:
it(...
module(...
$exceptionHandlerProvider.mode('log');
});
inject(...
);
});
Diffstat (limited to 'src/ngMock/angular-mocks.js')
| -rw-r--r-- | src/ngMock/angular-mocks.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js index 724a7eff..9b48c6ef 100644 --- a/src/ngMock/angular-mocks.js +++ b/src/ngMock/angular-mocks.js @@ -202,6 +202,30 @@ angular.mock.$Browser.prototype = { * Mock implementation of {@link ng.$exceptionHandler} that rethrows or logs errors passed * into it. See {@link ngMock.$exceptionHandlerProvider $exceptionHandlerProvider} for configuration * information. + * + * + * <pre> + * describe('$exceptionHandlerProvider', function() { + * + * it('should capture log messages and exceptions', function() { + * + * module(function($exceptionHandlerProvider) { + * $exceptionHandlerProvider.mode('log'); + * }); + * + * inject(function($log, $exceptionHandler, $timeout) { + * $timeout(function() { $log.log(1); }); + * $timeout(function() { $log.log(2); throw 'banana peel'; }); + * $timeout(function() { $log.log(3); }); + * expect($exceptionHandler.errors).toEqual([]); + * expect($log.assertEmpty()); + * $timeout.flush(); + * expect($exceptionHandler.errors).toEqual(['banana peel']); + * expect($log.log.logs).toEqual([[1], [2], [3]]); + * }); + * }); + * }); + * </pre> */ angular.mock.$ExceptionHandlerProvider = function() { |
