我想使用 passThrough() 将真实的 $http 数据用于我的单元测试。
这是我到目前为止所拥有的:
var should = chai.should();
beforeEach(module('myApp', 'ngMockE2E'));
beforeEach(inject(function(_$httpBackend_, _$rootScope_, _$http_) {
$scope = _$rootScope_;
$http = _$http_;
$httpBackend = _$httpBackend_;
}));
it.only('blah', function(done) {
$httpBackend.whenGET('/api/data').passThrough();
$scope.$apply(function() {
$http.get('/api/data').success(function(data) {
data.should.eql({"foo": "bar"});
done();
});
});
// Evidently not required with E2E
//$httpBackend.flush();
});
但这给出了一个错误:
Unexpected request: GET /api/data
No more request expected
Error: Unexpected request: GET /api/data
No more request expected
如果我删除应用程序,它会超时。