Skip to content

Commit 8c32ed0

Browse files
authored
feat(TestScheduler): expose frameTimeFactor property (#4977)
- Makes `frameTimeFactor` public so people do not have to cast in TypeScript - Deprecates `frameTimeFactor` on `VirtualTimeScheduler` as it is not used in that class, it is really only intended to be used for `TestScheduler` marble diagrams - Deprecates `index` on `VirtualTimeScheduler` because it is a leaked implementation detail - Adds documentation
1 parent 1fbee02 commit 8c32ed0

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

spec/schedulers/TestScheduler-spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ describe('TestScheduler', () => {
1414
expect(TestScheduler).to.be.a('function');
1515
});
1616

17+
it('should have frameTimeFactor set initially', () => {
18+
expect(TestScheduler.frameTimeFactor).to.equal(10);
19+
});
20+
1721
describe('parseMarbles()', () => {
1822
it('should parse a marble string into a series of notifications and types', () => {
1923
const result = TestScheduler.parseMarbles('-------a---b---|', { a: 'A', b: 'B' });

src/internal/scheduler/VirtualTimeScheduler.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,30 @@ import { SchedulerAction } from '../types';
55

66
export class VirtualTimeScheduler extends AsyncScheduler {
77

8-
protected static frameTimeFactor: number = 10;
8+
/** @deprecated remove in v8. `frameTimeFactor` is not used in VirtualTimeScheduler directly. */
9+
static frameTimeFactor = 10;
910

11+
/**
12+
* The current frame for the state of the virtual scheduler instance. The the difference
13+
* between two "frames" is synonymous with the passage of "virtual time units". So if
14+
* you record `scheduler.frame` to be `1`, then later, observe `scheduler.frame` to be at `11`,
15+
* that means `10` virtual time units have passed.
16+
*/
1017
public frame: number = 0;
18+
19+
/**
20+
* Used internally to examine the current virtual action index being processed.
21+
* @deprecated remove in v8. Should be a private API.
22+
*/
1123
public index: number = -1;
1224

25+
/**
26+
* This creates an instance of a `VirtualTimeScheduler`. Experts only. The signature of
27+
* this constructor is likely to change in the long run.
28+
*
29+
* @param SchedulerAction The type of Action to initialize when initializing actions during scheduling.
30+
* @param maxFrames The maximum number of frames to process before stopping. Used to prevent endless flush cycles.
31+
*/
1332
constructor(SchedulerAction: typeof AsyncAction = VirtualAction as any,
1433
public maxFrames: number = Number.POSITIVE_INFINITY) {
1534
super(SchedulerAction, () => this.frame);
@@ -43,10 +62,6 @@ export class VirtualTimeScheduler extends AsyncScheduler {
4362
}
4463
}
4564

46-
/**
47-
* We need this JSDoc comment for affecting ESDoc.
48-
* @nodoc
49-
*/
5065
export class VirtualAction<T> extends AsyncAction<T> {
5166

5267
protected active: boolean = true;

src/internal/testing/TestScheduler.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,38 @@ export type observableToBeFn = (marbles: string, values?: any, errorValue?: any)
2828
export type subscriptionLogsToBeFn = (marbles: string | string[]) => void;
2929

3030
export class TestScheduler extends VirtualTimeScheduler {
31+
/**
32+
* The number of virtual time units each character in a marble diagram represents. If
33+
* the test scheduler is being used in "run mode", via the `run` method, this is temporarly
34+
* set to `1` for the duration of the `run` block, then set back to whatever value it was.
35+
*/
36+
static frameTimeFactor = 10;
37+
38+
/**
39+
* @deprecated remove in v8. Not for public use.
40+
*/
3141
public readonly hotObservables: HotObservable<any>[] = [];
42+
43+
/**
44+
* @deprecated remove in v8. Not for public use.
45+
*/
3246
public readonly coldObservables: ColdObservable<any>[] = [];
47+
48+
/**
49+
* Test meta data to be processed during `flush()`
50+
*/
3351
private flushTests: FlushableTest[] = [];
52+
53+
/**
54+
* Indicates whether the TestScheduler instance is operating in "run mode",
55+
* meaning it's processing a call to `run()`
56+
*/
3457
private runMode = false;
3558

59+
/**
60+
*
61+
* @param assertDeepEqual A function to set up your assertion for your test harness
62+
*/
3663
constructor(public assertDeepEqual: (actual: any, expected: any) => boolean | void) {
3764
super(VirtualAction, defaultMaxFrame);
3865
}

0 commit comments

Comments
 (0)