gpt4 book ai didi

javascript - 使用 Angular JS 进行 Jasmine 测试用例

转载 作者:行者123 更新时间:2023-12-02 16:58:39 25 4
gpt4 key购买 nike

我正在尝试测试休息服务,例如“/service/home/autolaunch?rnd=”查询参数“rnd”值始终是唯一的,以消除 Internet Explorer 缓存问题。在为上述后端服务编写 Jasmine 测试用例时,我收到错误“意外请求”,因为每次查询参数都不同。有没有办法在编写 Jasmine 测试时跳过查询参数。

在服务中调用是这样的-

http.get('/service/home/autolaunch', {params:{rnd:new Date().getTime()}}).then(
function(data){
// TO do
});

Jasmine 测试用例是 -

httpBackend.when('GET','/service/home/autolaunch').respond(-- to do);

即使按照以下方式定义测试用例-

httpBackend.when('GET','/service/home/autolaunch?rnd=' + new Date().getTime()).respond(-- to do);

仍然收到意外请求。

调试后发现时间戳值不同。

最佳答案

您可以在 $httpBackend.expectGet() 方法中使用正则表达式:

var regex = new RegExp('/service/home/autolaunch\\?rnd=.*');
httpBackend.expectGET(regex).respond(...);

关于javascript - 使用 Angular JS 进行 Jasmine 测试用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25958733/

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