In my view I have loading animation that is displayed until I receive a response from the API.
//Displayed before we've received API response
<p ng-if="vm.vehicles == null">Loading ...</p>
//Displayed once we received response for the API
<table ng-if="vm.vehicles">
<tr ng-repeat="vehicle.vm.vehicles">...</tr>
To do my testing, I use the $httpBackend
Angular module. Something like this:
$httpBackend.whenGET('api/vehicles').respond({vehicles: [...]});
Problem
I want to write a test to check the the loading animation is displayed.
I tried:
expect(ptor.isElementPresent(By.cssContainingText('p', 'Loading'))).to.eventually.be.true;`
but i does't pass. So i think I need to conditionally delay the response I get from $httpBackend.
I found this blog post http://endlessindirection.wordpress.com/2013/05/18/angularjs-delay-response-from-httpbackend/
However, inserting that config method made all my tests fails (I think because the templates aren't loaded in time), it delays ALL responses so it's not really what I need.
So how can I delay the response for that one call? Ideally, I would like to delay it only for that test.