Description
Which @angular/* package(s) are relevant/related to the feature request?
@angular/core/testing
Description
I'm making use of fakeAsync
extensively for my tests and I like the control it gains me, so I want to express my gratitude towards the development and maintenance of this functionality.
I've noticed that the fake async Scheduler
has a flush function that exposes a parameter flushPeriodic
which allows the caller to flush any periodic tasks as well.
flush(limit = 20, flushPeriodic = false, doTick?: (elapsed: number) => void): number {
if (flushPeriodic) {
return this.flushPeriodic(doTick);
} else {
return this.flushNonPeriodic(limit, doTick);
}
}
However, the flush
function imported from @angular/core/testing
does not make use of that parameter and instead just goes along with the default value.
export function flush(maxTurns?: number): number {
if (fakeAsyncTestModule) {
return fakeAsyncTestModule.flush(maxTurns);
}
throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
}
I was just wondering if there is a specific reason for this? It would be really helpful to have the ability to pass that to my flush
-es as well, instead of having to tick
for the periodic tasks.
Proposed solution
I'm not sure it would be so simple as this, but I guess what I'm asking requires a change like so:
export function flush(maxTurns?: number, flushPeriodic = false): number {
if (fakeAsyncTestModule) {
return fakeAsyncTestModule.flush(maxTurns, flushPeriodic);
}
throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
}
Keeping the default value false as to not change anything in the existing implementation.
Alternatives considered
I'd like any possible way to access that particular functionality, to flush
, be it a change to the existing function or a new function flushPeriodic
that would to exactly that.