AngularJS&Karma Jasmine-如果verifyNoOutstanding Expection(

AngularJS & Karma-Jasmine - Not working if verifyNoOutstandingExpectation(); or verifyNoOutstandingRequest(); stands alone

本文关键字:如果 verifyNoOutstanding Expection Jasmine- Karma amp AngularJS      更新时间:2023-09-26

我有一个http请求没有被刷新,所以当我有这样的时

afterEach(function(){
      $httpBackend.verifyNoOutstandingExpectation();
      $httpBackend.verifyNoOutstandingRequest();
});

它按预期工作,我得到

错误:未清理的请求:1

错误消息来自$httpBackend.verifyNoOutstandingRequest();,但当我有这样的时

afterEach(function(){
    $httpBackend.verifyNoOutstandingRequest();
});

不会引发任何错误

为什么会这样?我必须总是把这两种方法放在一起吗?

在AngularJS文档中,它说

verifyNoOutstandingExpectation();

验证是否已发出通过预期api定义的所有请求。如果没有发出任何请求,verifyNoOutstandingExpection将引发异常。

因此,这可能是您没有定义任何期望调用,而是使用verifyNoOutstandingExpection的原因,因此它抛出了一个异常。