-
Notifications
You must be signed in to change notification settings - Fork 407
Feature request: FakeAsync should have a flush function #735
Comments
cc @mhevery does this design look good? |
Return value could be the length of time moved. |
I think I'd prefer if it moved to the next timeout. Something like |
I think I prefer flushing all of them. Here's how I see it: if you're testing some behavior you don't control, you just want to move time forward until stuff is done. If you only advanced to the next timeout, you'd need to do that X times, where X is a guessing game. If you control the behavior, you're in a position to use We could, potentially, also add a |
Yeah, makes sense. I was thinking for behavior you don't control, you might want to assert something after each event or that timeouts occur in some particular order. I think you're right, though, in those situations it'd probably just make more sense to use What about polling behavior where there's always a timeout being scheduled? Would we be able to detect that and give a helpful error message? Maybe something like be |
The `flush` method advances time until all non-periodic timers are cleared from the queue. It has a configurable limit (default 20) of tasks that will be run before it gives up and throws an error, in order to avoid infinite loops when polling timeouts are present. Closes angular#735
In my PR, I add |
The `flush` method advances time until all non-periodic timers are cleared from the queue. It has a configurable limit (default 20) of tasks that will be run before it gives up and throws an error, in order to avoid infinite loops when polling timeouts are present. Closes angular#735
The `flush` method advances time until all non-periodic timers are cleared from the queue. It has a configurable limit (default 20) of tasks that will be run before it gives up and throws an error, in order to avoid infinite loops when polling timeouts are present. Closes angular#735
LGTM. It feels a little more natural to me to do it by max elapsed time. I'm thinking of page-level tests as being kind of black box, so you'd say "I don't know what tasks this thing is going to start, but I do know it shouldn't take longer than 500ms" or something. But limiting it based on the number of tasks also seems reasonable, and as long as there's a good error message it's all good. |
The `flush` method advances time until all non-periodic timers are cleared from the queue. It has a configurable limit (default 20) of tasks that will be run before it gives up and throws an error, in order to avoid infinite loops when polling timeouts are present. Closes #735
This function would simulate moving time forward until the queue of pending macrotasks is cleared.
With multiple setTimeouts, it would move to the furthest in the future.
It would clear chained setTimeouts.
Intervals would not affect it.
For example (using end-user syntax based on Angular's helpers):
The text was updated successfully, but these errors were encountered: