unit-testing - 在 $http 的错误函数中抛出错误导致 $digest 已经在单元测试中进行

标签 unit-testing angularjs jasmine karma-runner

这是一个显示问题的 plunker:

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

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

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

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

最佳答案

问题是 mock $exceptionHandler 服务默认会重新抛出异常。所以你的异常导致 $rootScope.$apply 在中间中止。

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

关于unit-testing - 在 $http 的错误函数中抛出错误导致 $digest 已经在单元测试中进行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17593767/

相关文章:

angularjs - Restangular - 嵌套资源

javascript - 在 ui-bootstrap modal dismiss 上调用模态中定义的函数

unit-testing - Visual Studio 2012中的单元测试问题

python - unittest 和 nose 框架之间的冲突

python - 单元测试和元类 : automatic test_* method generation

c# - TDD/注入(inject)和信息隐藏之间的斗争 - 可能的妥协?

angularjs - ng-Map 未在信息窗口中显示文本

javascript - 多个异步测试 Jasmine

angularjs - 如何测试指令链接中的功能

testing - 按顺序运行 Jasmine 测试