mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
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(...
);
});
This commit is contained in:
parent
a179a9a96e
commit
224d7d6e90
2 changed files with 26 additions and 1 deletions
|
|
@ -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){
|
||||
|
|
|
|||
24
src/ngMock/angular-mocks.js
vendored
24
src/ngMock/angular-mocks.js
vendored
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue