You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
I have the following test for a service that internally uses $timeout:
describe('Beat',function(){varnagBeat,$timeout;beforeEach(module('nag.beat'));beforeEach(inject(function($injector){nagBeat=$injector.get('nagBeat');$timeout=$injector.get('$timeout');}));it('should be able to add and remove beat',function(){vartest=0;nagBeat.add('increment',function(){test+=1;},50);//wait and flush timeout 2 timeswaits(50);$timeout.flush();waits(50);$timeout.flush();expect(test).toEqual(2);expect(nagBeat.activeBeatsCount()).toEqual(1);nagBeat.remove('increment');waits(50);$timeout.flush();expect(nagBeat.activeBeatsCount()).toEqual(0);});});
Now everything works fine until I get to the last set of waits/$timeout.flush(). This test fails with the error:
No deferred tasks to be flushed
However that is the desired result, the timeout should no longer exist after I call nagBeat.remove().
Now maybe there is a way to test this functionality but when I remove the throw Error() from angular-mocks.js and run the test again it passes fine.
If there is a better way to test this type of functionality, please let me know. If not I would be happy to make this change.
davidshepherd7, alexander-elgin, zkendall and moshfeu