diff options
| author | Fred Sauer | 2013-01-16 18:01:03 -0800 | 
|---|---|---|
| committer | Misko Hevery | 2013-01-17 23:08:39 -0800 | 
| commit | 224d7d6e9023395e9bf3f7217984c04fd550f4e7 (patch) | |
| tree | a85d8d39c365e90feded2c84c66f0809308a5372 /src/ngMock | |
| parent | a179a9a96eda5c566bda8a70ac8a75822c936a68 (diff) | |
| download | angular.js-224d7d6e9023395e9bf3f7217984c04fd550f4e7.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')
| -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 757d0d55..c0b499ef 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() { | 
