I play with AngularJS unit testing when developing a Feed application (RSS). Feed can retrieve remote rss data by analyzing it and storing parsed items. To test the rss request, I use $ httpBackend mock:
beforeEach(inject(function (_$httpBackend_, _feedMock_, _mockConfig_) { _$httpBackend_.when('GET', _mockConfig_.FEED_URL).respond(_feedMock_); }));
and then below
$httpBackend.expectGET(mockConfig.FEED_URL); feed.fetch(); $httpBackend.flush();
It works great.
But I need Feed to be able to update its state by retrieving updated rss data and adding new elements. So, Feed makes the same request, but receives new updated data. I am trying to recreate the server definition as follows:
$httpBackend.when('GET', _mockConfig_.FEED_URL).respond(feedMockUpdated);
and then do the same operation with the wait and flash, but the response is $ httpBackend with the old data (feedMock), not the new one (feedMockUpdated). How can I make $ httpBackend to respond with different data on the same request?
source share