[英]jasmine test cases with angular js
我正在尝试测试其余的服务,例如“ / service / home / autolaunch?rnd =“。查询参数“ rnd”的值始终是唯一的,可以摆脱Internet Explorer缓存问题。 在为上述后端服务编写茉莉花测试用例时,由于每次查询参数都不同,因此出现错误“意外请求”。 有什么办法可以在编写茉莉花测试时跳过查询参数。
在使用中,呼叫就像这样-
http.get('/service/home/autolaunch', {params:{rnd:new Date().getTime()}}).then(
function(data){
// TO do
});
茉莉花测试用例是-
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(...);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.