View source Improve this doc

$exceptionHandler

service in module ngMock

Description

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

  1. describe('$exceptionHandlerProvider', function() {
  2.  
  3. it('should capture log messages and exceptions', function() {
  4.  
  5. module(function($exceptionHandlerProvider) {
  6. $exceptionHandlerProvider.mode('log');
  7. });
  8.  
  9. inject(function($log, $exceptionHandler, $timeout) {
  10. $timeout(function() { $log.log(1); });
  11. $timeout(function() { $log.log(2); throw 'banana peel'; });
  12. $timeout(function() { $log.log(3); });
  13. expect($exceptionHandler.errors).toEqual([]);
  14. expect($log.assertEmpty());
  15. $timeout.flush();
  16. expect($exceptionHandler.errors).toEqual(['banana peel']);
  17. expect($log.log.logs).toEqual([[1], [2], [3]]);
  18. });
  19. });
  20. });