I have an AngularJS service which performs an $http GET request and caches the response locally. It is designed to handle the multiple calls happening simultaneously, such that only the data from the final call is cached.
Specifically, if the following happens:
- Request A Started
- Request B Started
- Request B Completed
- Request A Completed
The result is that the response of request B is cached, because it was initiated last.
However I'm having trouble unit testing this in Jasmine.
I can set-up two $httpBackend.expectGET() expectations, but I can only flush them in the order they are requested.
Essentially I need to be able to so 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?