2013-10-21 50 views
0

我有一個單元測試,我正在檢查服務使用$ http輪詢URL。第一次我想返回一個值,這將導致服務等待10秒(使用$超時),然後再次輪詢。第二次我想返回一個值,這將停止輪詢服務。用相同的參數調用httpBackend,但返回不同的值

當我這樣做

httpBackend.expectGET(url).respond(200, { status: 'busy'}); 
httpBackend.expectGET(ulr).respond(200, { status: 'complete}'); 
service.poll(); 
httpBackend.flush(); 
timeout.flush(); 

httpBackend.verifyNoAllRequests(); 

但是它從來沒有得到的驗證部分。當我做timeout.flush()我得到

Unsatisfied requests: GET /url/status/check 
+0

也許你'service.poll()'做是不是一個額外的URL請求嘲笑? –

+0

不,只有這兩個。我使用Chrome開發人員工具瀏覽了它 – uriDium

回答

0

你試過:

httpBackend.expectGET(url).respond(200, { status: 'busy'}); 
service.poll(); 
httpBackend.flush(); 
timeout.flush(); 
httpBackend.expectGET(url).respond(200, { status: 'complete}'); 
httpBackend.flush(); 
相關問題