MCPcopy Create free account
hub / github.com/angular/angular / verifyTimeline

Function verifyTimeline

packages/core/test/acceptance/defer_spec.ts:105–146  ·  view source on GitHub ↗

* Allows to verify behavior of defer blocks by providing a set of * [time, expected output] pairs. Also allows to provide a function * instead of an expected output string, in which case the function * is invoked at a specified time.

(
  fixture: ComponentFixture<unknown>,
  ...slots: Array<[time: number, expected: string | VoidFunction]>
)

Source from the content-addressed store, hash-verified

103 * is invoked at a specified time.
104 */
105async function verifyTimeline(
106 fixture: ComponentFixture<unknown>,
107 ...slots: Array<[time: number, expected: string | VoidFunction]>
108) {
109 let actualTime = 0;
110 for (let i = 0; i < slots.length; i++) {
111 const targetVirtualTime = slots[i][0];
112 const slotValue = slots[i][1];
113
114 if (typeof slotValue === 'function') {
115 const waitTime = Math.max(0, targetVirtualTime - actualTime);
116 if (waitTime > 0) {
117 await timeout(waitTime);
118 actualTime += waitTime;
119 }
120 slotValue();
121 } else {
122 const waitTime = Math.max(0, targetVirtualTime - actualTime);
123 if (waitTime > 0) {
124 await timeout(waitTime);
125 actualTime += waitTime;
126 }
127
128 let actual = '';
129 let waited = 0;
130 const maxWait = 40; // max ms to poll for the expected state
131
132 while (waited <= maxWait) {
133 fixture.detectChanges();
134 actual = fixture.nativeElement.textContent.trim();
135 if (actual === slotValue) {
136 break;
137 }
138 await timeout(1);
139 waited += 1;
140 actualTime += 1;
141 }
142
143 expect(actual).withContext(`${targetVirtualTime}ms (actual ${actualTime}ms)`).toBe(slotValue);
144 }
145 }
146}
147
148class FakeTimerScheduler {
149 cbs: VoidFunction[] = [];

Callers 1

defer_spec.tsFile · 0.85

Calls 4

timeoutFunction · 0.90
withContextMethod · 0.80
maxMethod · 0.45
detectChangesMethod · 0.45

Tested by

no test coverage detected