I have an AngularJS service that executes a $ http GET request and caches the response locally. It is designed to handle multiple calls simultaneously, so only data from the last call is cached.
In particular, if the following occurs:
- Launch request
- Request B started
- Request B completed.
- Request Completed
The result is that the response of request B is cached since it was the last initiated.
However, I had a problem testing this in Jasmine.
I can set up two wait $ httpBackend.expectGET (), but I can only clear them in the order in which they are requested.
Essentially, I need to be able to do something like this:
$httpBackend.expectGET('/one').respond(200, data1); $httpBackend.expectGET('/two').respond(200, data2); myService.doSomething('/one'); myService.doSomething('/two'); $httpBackend.flush('/two'); $httpBackend.flush('/one'); expect(myService.data).toBe(data2);
Can anyone suggest a neat way to achieve this?
James thurley
source share