我有一个尚未刷新的 http 请求,所以当我有这样的请求时
afterEach(function(){
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
它按预期工作,我明白了
Error: Unflushed requests: 1
错误信息来自$httpBackend.verifyNoOutstandingRequest();
,但是当我有这样的时候
afterEach(function(){
$httpBackend.verifyNoOutstandingRequest();
});
不会抛出任何错误。
为什么会这样?我是否必须始终将这两种方法放在一起?
最佳答案
在 AngularJS 文档中说
verifyNoOutstandingExpectation();
验证是否已发出通过 expect api 定义的所有请求。如果未发出任何请求,verifyNoOutstandingExpectation 将引发异常。
所以这可能是您没有定义任何 expect 调用但使用 verifyNoOutstandingExpectation 的原因,因此它抛出异常。
关于javascript - AngularJS 和 Karma-Jasmine - 如果 verifyNoOutstandingExpectation() 不工作;或 verifyNoOutstandingRequest();独立,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31043275/