2014-09-21 123 views
0

我試圖測試其他服務,如「/服務/ home/autolaunch?rnd =」 查詢參數「rnd」值始終是唯一的擺脫Internet Explorer緩存問題。 在爲上述後端服務編寫茉莉花測試用例時,我收到錯誤「意外請求」,因爲查詢參數每次都不相同。有沒有辦法在編寫茉莉花測試時跳過查詢參數。茉莉花測試案例與角js

在服務呼叫就像是覺得─

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

茉莉花測試用例是 -

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

即使在以下way-

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

定義測試用例仍然得到意外的請求。

做完調試後才知道時間戳的值不同。

回答

2

可以在$httpBackend.expectGet()方法使用正則表達式

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

感謝丹尼斯。成功地執行測試。 – prad121 2014-09-21 12:16:30

+0

@ prad121很高興能幫到你。如果有幫助,請「接受」這個答案。 – 2014-09-21 12:37:02