运行我的测试用例Error: Unexpected request: POST data/json/api.json
it("should $watch value", function(){
var request = '/data/json/api.json';
$httpBackend.expectPOST(request).respond(200);
var iplScore = 10;
var controller = new controller(iplScore);
$scope.cricketScore = 0;
$scope.$digest();
$scope.cricketScore = 1;
assert.equal(iplScore, 0);
});
以下是我的控制器代码:
$scope.$watch("cricketScore", function(newValue, oldValue) {
$scope.iplScore = oldValue;
});
任何人都可以帮助我解决为什么我会收到上述错误,即使我通过$httpBackend
嘲笑了api
答案 0 :(得分:1)
你没有嘲笑你的API调用。将以下内容放入beforeEach()
:
beforeEach(function () {
$httpBackend.when('POST', '/data/json/api.json').respond(200, {
status: "success"
});
});