【问题标题】:Throw error in error function of $http causes $digest already in progress in unit test在 $http 的错误函数中抛出错误导致 $digest 已经在单元测试中进行
【发布时间】:2013-07-11 12:45:51
【问题描述】:

这是一个显示问题的 plunker:

http://plnkr.co/edit/J8zRIj?p=preview

这是一个 plunker,错误在 scripts.js 和 scripts.spec.js 中都被注释掉了,我不再收到 $digest 错误:

http://plnkr.co/edit/jCRlwf?p=preview

当错误不在 $http 请求的回调中时,抛出和测试错误似乎有效。有人知道为什么这可能不起作用吗?

【问题讨论】:

    标签: unit-testing angularjs jasmine karma-runner


    【解决方案1】:

    问题是模拟 $exceptionHandler 服务默认重新抛出异常。因此,您的异常导致 $rootScope.$apply 在中间中止。

    一种解决方案是将模拟 $exceptionHandlerProvider 切换到“日志”模式,然后检查 $exceptionHandler.errors。 See here.

    【讨论】:

    猜你喜欢
    • 2015-07-26
    • 2013-01-28
    • 2014-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-31
    • 1970-01-01
    相关资源
    最近更新 更多