我使用jasmine-ajax模拟一个ajax请求,如下所示
jasmine.Ajax.requests.mostRecent().respondWith({
"status": 200,
"responseText": '{}'
});我正在尝试获取传递给ajax成功回调的请求对象的'Location‘头,如下所示:
success(function(data, textStatus, request) {
var url = request.getResponseHeader('Location');
url = url.substring(...);
}但是它返回null,并且jasmine测试失败,因为在null上调用了substring函数。我该怎么办?注意:如果ajax请求没有被模仿,我可以很好地访问'Location‘头。
发布于 2016-01-14 06:26:09
您可以将该函数添加到要返回的对象中:
jasmine.Ajax.requests.mostRecent().respondWith({
"status": 200,
"responseText": '{}',
"getResponseHeader": function(arg) { return 'customlocation';}
});https://stackoverflow.com/questions/34737030
复制相似问题