I've used $timeout with a delay of e.g. 600ms in some service code. In the according test I want to assert that the code really does what it is expected to do after the given 600 ms. Is there any way to progress in time with a certain amount of time (similar to jasmine.Clock.tick(600))? I only know about $timeout.flush(), but that fires everything currently in the $timeout-queue.
Add a comment
|
1 Answer
In AngularJS version 1.2 you can do $timeout.flush(600), which is analogous to Jasmine's jasmine.Clock.tick(600).
In addition to that Angular 1.2 provides a very handy $timeout.flushNext(msec) method. It differs from the flush(msec) in that that instead of simply putting a clock given time ahead for you to then check if an expected thing happened or not, the flushNext() method does both tasks at once. It puts a clock ahead up until the next deferred event is fired and then verifies that the elapsed time equals the given one.
3 Comments
alex3683
Good to see that this is added for version 1.2. It doesn't help us though, as we are currently stuck to version 1.0. Nevertheless thanks for pointing out that this feature will be available.
Mark Seemann
AFAICT, the
flushNext function seems to be gone, but the flush function is still there.