我試圖測試HTTP調用之前等待無極代碼:
代碼:
function foo() {
return Parse.Promise.as(1).then(function(one) {
return $http.get('/bar');
});
}
測試:
describe('foo', function() {
it('gets', function(done) {
$httpBackend.expect('GET', '/bar').respond(200);
foo().then(function(res) {
expect(res.status).to.be.equal(200);
done();
});
$httpBackend.flush();
});
});
錯誤:
1) gets
foo
No pending request to flush !
我的猜測是因爲Parse.Promise
延遲了承諾分辨率,並且在調用$httpBackend.flush
時沒有發出http請求。
有沒有解決方法?
這會破壞你的代碼的執行順序,你可能會得到莫名其妙的故障。 –
只有在需要時纔可以禁用單個測試。這是我搜索數小時後才能使其工作的唯一途徑。 – gfpacheco