aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFred Sauer2013-01-16 18:01:03 -0800
committerMisko Hevery2013-01-17 23:08:39 -0800
commit224d7d6e9023395e9bf3f7217984c04fd550f4e7 (patch)
treea85d8d39c365e90feded2c84c66f0809308a5372 /src
parenta179a9a96eda5c566bda8a70ac8a75822c936a68 (diff)
downloadangular.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')
-rw-r--r--src/ng/exceptionHandler.js3
-rw-r--r--src/ngMock/angular-mocks.js24
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 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() {