如果我将呼叫保持在$httpBackend.flush()
原处,则测试将失败No Pending Requests
,但预期会通过。如果我注释掉flush
电话,期望会失败。当我在获取日期的服务中放置一个断点时,它被调用并且承诺正在解决,我可以进入addIssues
它被调用。会不会是另一个导致它的测试?
it("should pass",
function() {
scope.issues = [];
scope.requestChanges.issues = [
{
title: "File Mismatch",
affects_2d_file: true,
affects_3d_file: true,
resolved_at: null
},
{
title: "Missing Files",
affects_2d_file: true,
affects_3d_file: true,
resolved_at: null
}
];
spyOn(TEST.$state, "go");
spyOn(TEST.notification_service, "pushSuccessMessage");
TEST.$httpBackend.expectPOST("/some/url")
.respond(200,{
part_issues: scope.requestChanges.issues
});
scope.addIssues(); //this makes makes the http request.
TEST.$httpBackend.flush(); //expects pass, but no pending request
scope.part.issues.forEach(function(e, i) {
var issue = e;
var change = scope.requestChanges.issues[i];
expect(_.isEqual(issue, change)).toBe(true);
});
//TEST.$httpBackend.flush(); expects fail
});
我确实有TEST.$httpBackend.expectGET("/some/url").respond(200,part)
一个beforeEach。flush
(在 beforeEach 中没有调用)