错误:意外请求:POST业力

时间:2016-01-17 13:46:28

标签: javascript angularjs karma-runner karma-mocha

运行我的测试用例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

1 个答案:

答案 0 :(得分:1)

没有嘲笑你的API调用。将以下内容放入beforeEach()

beforeEach(function () {
    $httpBackend.when('POST', '/data/json/api.json').respond(200, {
        status: "success"
    });
});