ngMock.$exceptionHandler

Improve this Doc View Source $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.

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]]);
    });
  });
});

© 2010–2016 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://code.angularjs.org/1.4.14/docs/api/ngMock/service/$exceptionHandler

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部