ngMock.$exceptionHandler

  1. $exceptionHandlerProvider
  2. service in module ngMock

Mock implementation of $exceptionHandler that rethrows or logs errors passed to it. See $exceptionHandlerProvider for configuration information.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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]]);
    });
  });
});
doc_AngularJS
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.