diff options
| -rw-r--r-- | src/ng/exceptionHandler.js | 3 | ||||
| -rw-r--r-- | src/ngMock/angular-mocks.js | 24 | 
2 files changed, 26 insertions, 1 deletions
diff --git a/src/ng/exceptionHandler.js b/src/ng/exceptionHandler.js index 4378e102..f74e09ee 100644 --- a/src/ng/exceptionHandler.js +++ b/src/ng/exceptionHandler.js @@ -11,11 +11,12 @@   * the browser console.   *   * In unit tests, if `angular-mocks.js` is loaded, this service is overridden by - * {@link ngMock.$exceptionHandler mock $exceptionHandler} + * {@link ngMock.$exceptionHandler mock $exceptionHandler} which aids in testing.   *   * @param {Error} exception Exception associated with the error.   * @param {string=} cause optional information about the context in which   *       the error was thrown. + *   */  function $ExceptionHandlerProvider() {    this.$get = ['$log', function($log){ 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() {  | 
