我正在尝试使用 Jasmine 异步测试来测试包装在 AngularJS 服务中的 REST API。我知道,我应该并且现在在服务器上的 API 上运行测试,并使用模拟 $httpBackend 来测试服务,但我仍然想知道如何在需要的地方进行异步测试。
我遇到的问题是我的延迟(由 $http 返回)似乎永远无法解决。跳过服务并尝试简单地使用 $http 有同样的问题。我在这里做错了什么:
describe('Jasmine + Angular + $http', function() {
    var injector; 
    beforeEach(function() {
        injector = angular.injector(['ng']);
    });
    it('can be tested', function() {
        injector.invoke(function($http) {
            var complete = false;
            runs(function() {
                $http.get('...').then(function(res) {
                    complete = true;
                });
            });
            waitsFor(function() {
                return complete;
            }, 'query to complete', 5000);
            runs(function() {
                expect(complete).toEqual(true);
            });
        });
    });
});
(我正在使用 grunt-contrib-jasmine 来运行测试)