我有以下代码正在使用sinon存根进行测试。
updateRequest = httpService.get(options).done(function (response) {
}).fail(function (error) {
});
在现实世界中,httpService.get(options)返回$ .ajax(options)
在测试中,我正在使用
this.httpGetStub = sinon.stub(httpService, 'get');
this.httpGetStub.withArgs(myOptions).returns($.Deferred().resolve(testResponse));
我已经获得了很好的报道,到目前为止所有测试都可以正常工作。
对于上一次测试,我想测试以下代码:
const _stopUpdates = function () {
if (updateRequest) {
updateRequest.abort();
}
return;
};
运行测试时出现此错误:
updateRequest.abort不是函数
所以我猜我需要为我的httpGetStub的返回值添加一个abort()的存根。我尝试了一些选项,但似乎无济于事。
这一定是常见问题,有什么想法要解决吗?