Angularjs Angular JS单元测试$httpBackend规范没有期望

Angularjs Angular JS单元测试$httpBackend规范没有期望,angularjs,unit-testing,jasmine,Angularjs,Unit Testing,Jasmine,我有一个单元测试,其中唯一的期望是进行http调用。我使用$httpBackend.expect()来实现此目的。这很好,如果没有发出http请求,单元测试就会失败(这很好),如果发出http请求,单元测试就会通过 问题是,即使它通过了测试,Jasmine spec runner对这个单元测试显示“spec没有期望”,这让我觉得我没有使用推荐的方法来测试http调用是否被执行。如何避免看到此消息 示例测试: it('should call sessioncheck api', function

我有一个单元测试,其中唯一的期望是进行http调用。我使用$httpBackend.expect()来实现此目的。这很好,如果没有发出http请求,单元测试就会失败(这很好),如果发出http请求,单元测试就会通过

问题是,即使它通过了测试,Jasmine spec runner对这个单元测试显示“spec没有期望”,这让我觉得我没有使用推荐的方法来测试http调用是否被执行。如何避免看到此消息

示例测试:

it('should call sessioncheck api', function () {
    inject(function ($injector, SessionTrackerService) {
        $httpBackend = $injector.get('$httpBackend');

        var mockResponse = { IsAuthenticated: true, secondsRemaining: 100 };
        $httpBackend.expect('GET', 'API/authentication/sessioncheck')
            .respond(200, mockResponse);

        SessionTrackerService.Start();

        jasmine.clock().tick(30001);
        $httpBackend.flush();
    });
});

尝试删除jasmine.clock().tick(30001)


如果在SessionTrackerService.Start方法中没有超时,则此代码中的超时量过大。我将调用包装为flush,如下所示:

expect($httpBackend.flush).not.toThrow();
我更喜欢这种方法,因为测试代码清楚地说明了调用flush时“应该”发生什么。例如:

it('should call expected url', inject(function($http) {
    // arrange
    $httpBackend.expectGET('http://localhost/1').respond(200);

    // act
    $http.get('http://localhost/1');

    // assert
    expect($httpBackend.flush).not.toThrow();

}));

可以在这里添加代码来说明一下吗?这可能是一个微小的错误,还有其他问题。谢谢。我试着在这里重现这种情况:。但是我没有收到警告,你能检查一下差异吗?我也有同样的问题。作为一种(非常难看的)解决方法,我在每个测试中添加了
expect(true).toBeTruthy()
,只是为了删除这个警告。我使用了一些不那么难看的东西:
expect('Suppress SPEC HAS NO expections')。toBeDefined()