From 224d7d6e9023395e9bf3f7217984c04fd550f4e7 Mon Sep 17 00:00:00 2001 From: Fred Sauer Date: Wed, 16 Jan 2013 18:01:03 -0800 Subject: 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(...  ); }); --- src/ngMock/angular-mocks.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/ngMock/angular-mocks.js') 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. + * + * + *
+ *   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]]);
+ *       });
+ *     });
+ *   });
+ * 
*/ angular.mock.$ExceptionHandlerProvider = function() { -- cgit v1.2.3