gpt4 book ai didi

javascript - 错误 : Unexpected request: POST karma

转载 作者:行者123 更新时间:2023-11-30 00:15:37 25 4
gpt4 key购买 nike

我在运行测试用例时遇到以下错误,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);
});

下面是我的 Controller 代码:

$scope.$watch("cricketScore", function(newValue, oldValue) {
$scope.iplScore = oldValue;
});

任何人都可以帮我解决为什么我会收到上述错误,即使我已经通过 $httpBackend

模拟了 api

最佳答案

没有模拟您的 API 调用。将以下内容放入 beforeEach() 中:

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

关于javascript - 错误 : Unexpected request: POST karma,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34839022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com