angularjs - Simulate Network Delay Jasmine Unit Test with $httpBackend -



angularjs - Simulate Network Delay Jasmine Unit Test with $httpBackend -

i have angularjs directive uses ng-mouseenter trigger phone call backend data. if phone call backend goes longer time, loading indicator presented.

i'd test loading indicator gets presented when network phone call taking longer specified period of time.

is there way simulate delay $httpbackend?

the code triggers these actions (inside directive):

scope.triggerpopover = function () { if (angular.element('.my-element-style').length === 0) { scope.detailprom = $timeout(function () { makerestcall(attrs.assetid || ''); }, 200); //waits length before makes phone call backend //we want loading icon come little bit later, because seem flicker //when calls fast scope.loadingprom = $timeout(function () { showloadingpopover(); }, 500); } };

the html/directive use

<article my-directive ng-mouseenter="triggerpopover();"></article>

in spec have in beforeeach()...

//mock backend phone call $httpbackend.whenget('/my/rest/endpoint') .respond(mockdata);

the test hover:

describe('hover tests', function () { it('hovering on article should create loading element appear while waiting restangular call', function () { runs(function() { //it takes few milliseconds mouseover react //due timeout in directive jquery(jquery('the-class-im-looking-for')[0]).mouseover(); }); waits(1000); runs(function() { console.log('i want know if loading popover launched, need set delay in $httpbackend?'); }) }); });

angularjs jasmine karma-jasmine httpbackend angular-mock

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -