使用相同的参数调用httpBackend但返回不同的值

时间:2013-10-21 07:43:27

标签: unit-testing angularjs jasmine

我有一个单元测试,我正在检查服务使用$ http轮询URL。第一次我要返回一个值,该值将导致服务等待10秒(使用$ timeout)然后再次轮询。第二轮我要返回一个值,该值将停止轮询服务。

当我这样做时

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

1 个答案:

答案 0 :(得分:0)

你试过了吗?

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