How to use scheduleCallback method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Scheduler-test.js

Source: Scheduler-test.js Github

copy
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @emails react-core
8 */
9
10'use strict';
11
12let Scheduler;
13let runWithPriority;
14let ImmediatePriority;
15let UserBlockingPriority;
16let NormalPriority;
17let LowPriority;
18let IdlePriority;
19let scheduleCallback;
20let cancelCallback;
21let wrapCallback;
22let getCurrentPriorityLevel;
23let shouldYield;
24
25describe('Scheduler', () => {
26  beforeEach(() => {
27    jest.resetModules();
28    jest.mock('scheduler', () => require('scheduler/unstable_mock'));
29
30    Scheduler = require('scheduler');
31
32    runWithPriority = Scheduler.unstable_runWithPriority;
33    ImmediatePriority = Scheduler.unstable_ImmediatePriority;
34    UserBlockingPriority = Scheduler.unstable_UserBlockingPriority;
35    NormalPriority = Scheduler.unstable_NormalPriority;
36    LowPriority = Scheduler.unstable_LowPriority;
37    IdlePriority = Scheduler.unstable_IdlePriority;
38    scheduleCallback = Scheduler.unstable_scheduleCallback;
39    cancelCallback = Scheduler.unstable_cancelCallback;
40    wrapCallback = Scheduler.unstable_wrapCallback;
41    getCurrentPriorityLevel = Scheduler.unstable_getCurrentPriorityLevel;
42    shouldYield = Scheduler.unstable_shouldYield;
43  });
44
45  it('flushes work incrementally', () => {
46    scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('A'));
47    scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('B'));
48    scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('C'));
49    scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('D'));
50
51    expect(Scheduler).toFlushAndYieldThrough(['A', 'B']);
52    expect(Scheduler).toFlushAndYieldThrough(['C']);
53    expect(Scheduler).toFlushAndYield(['D']);
54  });
55
56  it('cancels work', () => {
57    scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('A'));
58    const callbackHandleB = scheduleCallback(NormalPriority, () =>
59      Scheduler.unstable_yieldValue('B'),
60    );
61    scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('C'));
62
63    cancelCallback(callbackHandleB);
64
65    expect(Scheduler).toFlushAndYield([
66      'A',
67      // B should have been cancelled
68      'C',
69    ]);
70  });
71
72  it('executes the highest priority callbacks first', () => {
73    scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('A'));
74    scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('B'));
75
76    // Yield before B is flushed
77    expect(Scheduler).toFlushAndYieldThrough(['A']);
78
79    scheduleCallback(UserBlockingPriority, () =>
80      Scheduler.unstable_yieldValue('C'),
81    );
82    scheduleCallback(UserBlockingPriority, () =>
83      Scheduler.unstable_yieldValue('D'),
84    );
85
86    // C and D should come first, because they are higher priority
87    expect(Scheduler).toFlushAndYield(['C', 'D', 'B']);
88  });
89
90  it('expires work', () => {
91    scheduleCallback(NormalPriority, didTimeout => {
92      Scheduler.unstable_advanceTime(100);
93      Scheduler.unstable_yieldValue(`A (did timeout: ${didTimeout})`);
94    });
95    scheduleCallback(UserBlockingPriority, didTimeout => {
96      Scheduler.unstable_advanceTime(100);
97      Scheduler.unstable_yieldValue(`B (did timeout: ${didTimeout})`);
98    });
99    scheduleCallback(UserBlockingPriority, didTimeout => {
100      Scheduler.unstable_advanceTime(100);
101      Scheduler.unstable_yieldValue(`C (did timeout: ${didTimeout})`);
102    });
103
104    // Advance time, but not by enough to expire any work
105    Scheduler.unstable_advanceTime(249);
106    expect(Scheduler).toHaveYielded([]);
107
108    // Schedule a few more callbacks
109    scheduleCallback(NormalPriority, didTimeout => {
110      Scheduler.unstable_advanceTime(100);
111      Scheduler.unstable_yieldValue(`D (did timeout: ${didTimeout})`);
112    });
113    scheduleCallback(NormalPriority, didTimeout => {
114      Scheduler.unstable_advanceTime(100);
115      Scheduler.unstable_yieldValue(`E (did timeout: ${didTimeout})`);
116    });
117
118    // Advance by just a bit more to expire the user blocking callbacks
119    Scheduler.unstable_advanceTime(1);
120    expect(Scheduler).toHaveYielded([
121      'B (did timeout: true)',
122      'C (did timeout: true)',
123    ]);
124
125    // Expire A
126    Scheduler.unstable_advanceTime(4600);
127    expect(Scheduler).toHaveYielded(['A (did timeout: true)']);
128
129    // Flush the rest without expiring
130    expect(Scheduler).toFlushAndYield([
131      'D (did timeout: false)',
132      'E (did timeout: true)',
133    ]);
134  });
135
136  it('has a default expiration of ~5 seconds', () => {
137    scheduleCallback(NormalPriority, () => Scheduler.unstable_yieldValue('A'));
138
139    Scheduler.unstable_advanceTime(4999);
140    expect(Scheduler).toHaveYielded([]);
141
142    Scheduler.unstable_advanceTime(1);
143    expect(Scheduler).toHaveYielded(['A']);
144  });
145
146  it('continues working on same task after yielding', () => {
147    scheduleCallback(NormalPriority, () => {
148      Scheduler.unstable_advanceTime(100);
149      Scheduler.unstable_yieldValue('A');
150    });
151    scheduleCallback(NormalPriority, () => {
152      Scheduler.unstable_advanceTime(100);
153      Scheduler.unstable_yieldValue('B');
154    });
155
156    let didYield = false;
157    const tasks = [['C1', 100], ['C2', 100], ['C3', 100]];
158    const C = () => {
159      while (tasks.length > 0) {
160        const [label, ms] = tasks.shift();
161        Scheduler.unstable_advanceTime(ms);
162        Scheduler.unstable_yieldValue(label);
163        if (shouldYield()) {
164          didYield = true;
165          return C;
166        }
167      }
168    };
169
170    scheduleCallback(NormalPriority, C);
171
172    scheduleCallback(NormalPriority, () => {
173      Scheduler.unstable_advanceTime(100);
174      Scheduler.unstable_yieldValue('D');
175    });
176    scheduleCallback(NormalPriority, () => {
177      Scheduler.unstable_advanceTime(100);
178      Scheduler.unstable_yieldValue('E');
179    });
180
181    // Flush, then yield while in the middle of C.
182    expect(didYield).toBe(false);
183    expect(Scheduler).toFlushAndYieldThrough(['A', 'B', 'C1']);
184    expect(didYield).toBe(true);
185
186    // When we resume, we should continue working on C.
187    expect(Scheduler).toFlushAndYield(['C2', 'C3', 'D', 'E']);
188  });
189
190  it('continuation callbacks inherit the expiration of the previous callback', () => {
191    const tasks = [['A', 125], ['B', 124], ['C', 100], ['D', 100]];
192    const work = () => {
193      while (tasks.length > 0) {
194        const [label, ms] = tasks.shift();
195        Scheduler.unstable_advanceTime(ms);
196        Scheduler.unstable_yieldValue(label);
197        if (shouldYield()) {
198          return work;
199        }
200      }
201    };
202
203    // Schedule a high priority callback
204    scheduleCallback(UserBlockingPriority, work);
205
206    // Flush until just before the expiration time
207    expect(Scheduler).toFlushAndYieldThrough(['A', 'B']);
208
209    // Advance time by just a bit more. This should expire all the remaining work.
210    Scheduler.unstable_advanceTime(1);
211    expect(Scheduler).toHaveYielded(['C', 'D']);
212  });
213
214  it('continuations are interrupted by higher priority work', () => {
215    const tasks = [['A', 100], ['B', 100], ['C', 100], ['D', 100]];
216    const work = () => {
217      while (tasks.length > 0) {
218        const [label, ms] = tasks.shift();
219        Scheduler.unstable_advanceTime(ms);
220        Scheduler.unstable_yieldValue(label);
221        if (tasks.length > 0 && shouldYield()) {
222          return work;
223        }
224      }
225    };
226    scheduleCallback(NormalPriority, work);
227    expect(Scheduler).toFlushAndYieldThrough(['A']);
228
229    scheduleCallback(UserBlockingPriority, () => {
230      Scheduler.unstable_advanceTime(100);
231      Scheduler.unstable_yieldValue('High pri');
232    });
233
234    expect(Scheduler).toFlushAndYield(['High pri', 'B', 'C', 'D']);
235  });
236
237  it(
238    'continuations are interrupted by higher priority work scheduled ' +
239      'inside an executing callback',
240    () => {
241      const tasks = [['A', 100], ['B', 100], ['C', 100], ['D', 100]];
242      const work = () => {
243        while (tasks.length > 0) {
244          const task = tasks.shift();
245          const [label, ms] = task;
246          Scheduler.unstable_advanceTime(ms);
247          Scheduler.unstable_yieldValue(label);
248          if (label === 'B') {
249            // Schedule high pri work from inside another callback
250            Scheduler.unstable_yieldValue('Schedule high pri');
251            scheduleCallback(UserBlockingPriority, () => {
252              Scheduler.unstable_advanceTime(100);
253              Scheduler.unstable_yieldValue('High pri');
254            });
255          }
256          if (tasks.length > 0 && shouldYield()) {
257            Scheduler.unstable_yieldValue('Yield!');
258            return work;
259          }
260        }
261      };
262      scheduleCallback(NormalPriority, work);
263      expect(Scheduler).toFlushAndYield([
264        'A',
265        'B',
266        'Schedule high pri',
267        // Even though there's time left in the frame, the low pri callback
268        // should yield to the high pri callback
269        'Yield!',
270        'High pri',
271        // Continue low pri work
272        'C',
273        'D',
274      ]);
275    },
276  );
277
278  it('cancelling a continuation', () => {
279    const task = scheduleCallback(NormalPriority, () => {
280      Scheduler.unstable_yieldValue('Yield');
281      return () => {
282        Scheduler.unstable_yieldValue('Continuation');
283      };
284    });
285
286    expect(Scheduler).toFlushAndYieldThrough(['Yield']);
287    cancelCallback(task);
288    expect(Scheduler).toFlushWithoutYielding();
289  });
290
291  it('top-level immediate callbacks fire in a subsequent task', () => {
292    scheduleCallback(ImmediatePriority, () =>
293      Scheduler.unstable_yieldValue('A'),
294    );
295    scheduleCallback(ImmediatePriority, () =>
296      Scheduler.unstable_yieldValue('B'),
297    );
298    scheduleCallback(ImmediatePriority, () =>
299      Scheduler.unstable_yieldValue('C'),
300    );
301    scheduleCallback(ImmediatePriority, () =>
302      Scheduler.unstable_yieldValue('D'),
303    );
304    // Immediate callback hasn't fired, yet.
305    expect(Scheduler).toHaveYielded([]);
306    // They all flush immediately within the subsequent task.
307    expect(Scheduler).toFlushExpired(['A', 'B', 'C', 'D']);
308  });
309
310  it('nested immediate callbacks are added to the queue of immediate callbacks', () => {
311    scheduleCallback(ImmediatePriority, () =>
312      Scheduler.unstable_yieldValue('A'),
313    );
314    scheduleCallback(ImmediatePriority, () => {
315      Scheduler.unstable_yieldValue('B');
316      // This callback should go to the end of the queue
317      scheduleCallback(ImmediatePriority, () =>
318        Scheduler.unstable_yieldValue('C'),
319      );
320    });
321    scheduleCallback(ImmediatePriority, () =>
322      Scheduler.unstable_yieldValue('D'),
323    );
324    expect(Scheduler).toHaveYielded([]);
325    // C should flush at the end
326    expect(Scheduler).toFlushExpired(['A', 'B', 'D', 'C']);
327  });
328
329  it('wrapped callbacks have same signature as original callback', () => {
330    const wrappedCallback = wrapCallback((...args) => ({args}));
331    expect(wrappedCallback('a', 'b')).toEqual({args: ['a', 'b']});
332  });
333
334  it('wrapped callbacks inherit the current priority', () => {
335    const wrappedCallback = runWithPriority(NormalPriority, () =>
336      wrapCallback(() => {
337        Scheduler.unstable_yieldValue(getCurrentPriorityLevel());
338      }),
339    );
340
341    const wrappedUserBlockingCallback = runWithPriority(
342      UserBlockingPriority,
343      () =>
344        wrapCallback(() => {
345          Scheduler.unstable_yieldValue(getCurrentPriorityLevel());
346        }),
347    );
348
349    wrappedCallback();
350    expect(Scheduler).toHaveYielded([NormalPriority]);
351
352    wrappedUserBlockingCallback();
353    expect(Scheduler).toHaveYielded([UserBlockingPriority]);
354  });
355
356  it('wrapped callbacks inherit the current priority even when nested', () => {
357    let wrappedCallback;
358    let wrappedUserBlockingCallback;
359
360    runWithPriority(NormalPriority, () => {
361      wrappedCallback = wrapCallback(() => {
362        Scheduler.unstable_yieldValue(getCurrentPriorityLevel());
363      });
364      wrappedUserBlockingCallback = runWithPriority(UserBlockingPriority, () =>
365        wrapCallback(() => {
366          Scheduler.unstable_yieldValue(getCurrentPriorityLevel());
367        }),
368      );
369    });
370
371    wrappedCallback();
372    expect(Scheduler).toHaveYielded([NormalPriority]);
373
374    wrappedUserBlockingCallback();
375    expect(Scheduler).toHaveYielded([UserBlockingPriority]);
376  });
377
378  it("immediate callbacks fire even if there's an error", () => {
379    scheduleCallback(ImmediatePriority, () => {
380      Scheduler.unstable_yieldValue('A');
381      throw new Error('Oops A');
382    });
383    scheduleCallback(ImmediatePriority, () => {
384      Scheduler.unstable_yieldValue('B');
385    });
386    scheduleCallback(ImmediatePriority, () => {
387      Scheduler.unstable_yieldValue('C');
388      throw new Error('Oops C');
389    });
390
391    expect(() => expect(Scheduler).toFlushExpired()).toThrow('Oops A');
392    expect(Scheduler).toHaveYielded(['A']);
393
394    // B and C flush in a subsequent event. That way, the second error is not
395    // swallowed.
396    expect(() => expect(Scheduler).toFlushExpired()).toThrow('Oops C');
397    expect(Scheduler).toHaveYielded(['B', 'C']);
398  });
399
400  it('multiple immediate callbacks can throw and there will be an error for each one', () => {
401    scheduleCallback(ImmediatePriority, () => {
402      throw new Error('First error');
403    });
404    scheduleCallback(ImmediatePriority, () => {
405      throw new Error('Second error');
406    });
407    expect(() => Scheduler.unstable_flushAll()).toThrow('First error');
408    // The next error is thrown in the subsequent event
409    expect(() => Scheduler.unstable_flushAll()).toThrow('Second error');
410  });
411
412  it('exposes the current priority level', () => {
413    Scheduler.unstable_yieldValue(getCurrentPriorityLevel());
414    runWithPriority(ImmediatePriority, () => {
415      Scheduler.unstable_yieldValue(getCurrentPriorityLevel());
416      runWithPriority(NormalPriority, () => {
417        Scheduler.unstable_yieldValue(getCurrentPriorityLevel());
418        runWithPriority(UserBlockingPriority, () => {
419          Scheduler.unstable_yieldValue(getCurrentPriorityLevel());
420        });
421      });
422      Scheduler.unstable_yieldValue(getCurrentPriorityLevel());
423    });
424
425    expect(Scheduler).toHaveYielded([
426      NormalPriority,
427      ImmediatePriority,
428      NormalPriority,
429      UserBlockingPriority,
430      ImmediatePriority,
431    ]);
432  });
433
434  if (__DEV__) {
435    // Function names are minified in prod, though you could still infer the
436    // priority if you have sourcemaps.
437    // TODO: Feature temporarily disabled while we investigate a bug in one of
438    // our minifiers.
439    it.skip('adds extra function to the JS stack whose name includes the priority level', () => {
440      function inferPriorityFromCallstack() {
441        try {
442          throw Error();
443        } catch (e) {
444          const stack = e.stack;
445          const lines = stack.split('\n');
446          for (let i = lines.length - 1; i >= 0; i--) {
447            const line = lines[i];
448            const found = line.match(
449              /scheduler_flushTaskAtPriority_([A-Za-z]+)/,
450            );
451            if (found !== null) {
452              const priorityStr = found[1];
453              switch (priorityStr) {
454                case 'Immediate':
455                  return ImmediatePriority;
456                case 'UserBlocking':
457                  return UserBlockingPriority;
458                case 'Normal':
459                  return NormalPriority;
460                case 'Low':
461                  return LowPriority;
462                case 'Idle':
463                  return IdlePriority;
464              }
465            }
466          }
467          return null;
468        }
469      }
470
471      scheduleCallback(ImmediatePriority, () =>
472        Scheduler.unstable_yieldValue(
473          'Immediate: ' + inferPriorityFromCallstack(),
474        ),
475      );
476      scheduleCallback(UserBlockingPriority, () =>
477        Scheduler.unstable_yieldValue(
478          'UserBlocking: ' + inferPriorityFromCallstack(),
479        ),
480      );
481      scheduleCallback(NormalPriority, () =>
482        Scheduler.unstable_yieldValue(
483          'Normal: ' + inferPriorityFromCallstack(),
484        ),
485      );
486      scheduleCallback(LowPriority, () =>
487        Scheduler.unstable_yieldValue('Low: ' + inferPriorityFromCallstack()),
488      );
489      scheduleCallback(IdlePriority, () =>
490        Scheduler.unstable_yieldValue('Idle: ' + inferPriorityFromCallstack()),
491      );
492
493      expect(Scheduler).toFlushAndYield([
494        'Immediate: ' + ImmediatePriority,
495        'UserBlocking: ' + UserBlockingPriority,
496        'Normal: ' + NormalPriority,
497        'Low: ' + LowPriority,
498        'Idle: ' + IdlePriority,
499      ]);
500    });
501  }
502
503  describe('delayed tasks', () => {
504    it('schedules a delayed task', () => {
505      scheduleCallback(
506        NormalPriority,
507        () => Scheduler.unstable_yieldValue('A'),
508        {
509          delay: 1000,
510        },
511      );
512
513      // Should flush nothing, because delay hasn't elapsed
514      expect(Scheduler).toFlushAndYield([]);
515
516      // Advance time until right before the threshold
517      Scheduler.unstable_advanceTime(999);
518      // Still nothing
519      expect(Scheduler).toFlushAndYield([]);
520
521      // Advance time past the threshold
522      Scheduler.unstable_advanceTime(1);
523
524      // Now it should flush like normal
525      expect(Scheduler).toFlushAndYield(['A']);
526    });
527
528    it('schedules multiple delayed tasks', () => {
529      scheduleCallback(
530        NormalPriority,
531        () => Scheduler.unstable_yieldValue('C'),
532        {
533          delay: 300,
534        },
535      );
536
537      scheduleCallback(
538        NormalPriority,
539        () => Scheduler.unstable_yieldValue('B'),
540        {
541          delay: 200,
542        },
543      );
544
545      scheduleCallback(
546        NormalPriority,
547        () => Scheduler.unstable_yieldValue('D'),
548        {
549          delay: 400,
550        },
551      );
552
553      scheduleCallback(
554        NormalPriority,
555        () => Scheduler.unstable_yieldValue('A'),
556        {
557          delay: 100,
558        },
559      );
560
561      // Should flush nothing, because delay hasn't elapsed
562      expect(Scheduler).toFlushAndYield([]);
563
564      // Advance some time.
565      Scheduler.unstable_advanceTime(200);
566      // Both A and B are no longer delayed. They can now flush incrementally.
567      expect(Scheduler).toFlushAndYieldThrough(['A']);
568      expect(Scheduler).toFlushAndYield(['B']);
569
570      // Advance the rest
571      Scheduler.unstable_advanceTime(200);
572      expect(Scheduler).toFlushAndYield(['C', 'D']);
573    });
574
575    it('interleaves normal tasks and delayed tasks', () => {
576      // Schedule some high priority callbacks with a delay. When their delay
577      // elapses, they will be the most important callback in the queue.
578      scheduleCallback(
579        UserBlockingPriority,
580        () => Scheduler.unstable_yieldValue('Timer 2'),
581        {delay: 300},
582      );
583      scheduleCallback(
584        UserBlockingPriority,
585        () => Scheduler.unstable_yieldValue('Timer 1'),
586        {delay: 100},
587      );
588
589      // Schedule some tasks at default priority.
590      scheduleCallback(NormalPriority, () => {
591        Scheduler.unstable_yieldValue('A');
592        Scheduler.unstable_advanceTime(100);
593      });
594      scheduleCallback(NormalPriority, () => {
595        Scheduler.unstable_yieldValue('B');
596        Scheduler.unstable_advanceTime(100);
597      });
598      scheduleCallback(NormalPriority, () => {
599        Scheduler.unstable_yieldValue('C');
600        Scheduler.unstable_advanceTime(100);
601      });
602      scheduleCallback(NormalPriority, () => {
603        Scheduler.unstable_yieldValue('D');
604        Scheduler.unstable_advanceTime(100);
605      });
606
607      // Flush all the work. The timers should be interleaved with the
608      // other tasks.
609      expect(Scheduler).toFlushAndYield([
610        'A',
611        'Timer 1',
612        'B',
613        'C',
614        'Timer 2',
615        'D',
616      ]);
617    });
618
619    it('interleaves delayed tasks with time-sliced tasks', () => {
620      // Schedule some high priority callbacks with a delay. When their delay
621      // elapses, they will be the most important callback in the queue.
622      scheduleCallback(
623        UserBlockingPriority,
624        () => Scheduler.unstable_yieldValue('Timer 2'),
625        {delay: 300},
626      );
627      scheduleCallback(
628        UserBlockingPriority,
629        () => Scheduler.unstable_yieldValue('Timer 1'),
630        {delay: 100},
631      );
632
633      // Schedule a time-sliced task at default priority.
634      const tasks = [['A', 100], ['B', 100], ['C', 100], ['D', 100]];
635      const work = () => {
636        while (tasks.length > 0) {
637          const task = tasks.shift();
638          const [label, ms] = task;
639          Scheduler.unstable_advanceTime(ms);
640          Scheduler.unstable_yieldValue(label);
641          if (tasks.length > 0 && shouldYield()) {
642            return work;
643          }
644        }
645      };
646      scheduleCallback(NormalPriority, work);
647
648      // Flush all the work. The timers should be interleaved with the
649      // other tasks.
650      expect(Scheduler).toFlushAndYield([
651        'A',
652        'Timer 1',
653        'B',
654        'C',
655        'Timer 2',
656        'D',
657      ]);
658    });
659
660    it('schedules callback with both delay and timeout', () => {
661      scheduleCallback(
662        NormalPriority,
663        () => {
664          Scheduler.unstable_yieldValue('A');
665          Scheduler.unstable_advanceTime(100);
666        },
667        {delay: 100, timeout: 900},
668      );
669
670      Scheduler.unstable_advanceTime(99);
671      // Does not flush because delay has not elapsed
672      expect(Scheduler).toFlushAndYield([]);
673
674      // Delay has elapsed but task has not expired
675      Scheduler.unstable_advanceTime(1);
676      expect(Scheduler).toFlushExpired([]);
677
678      // Still not expired
679      Scheduler.unstable_advanceTime(899);
680      expect(Scheduler).toFlushExpired([]);
681
682      // Now it expires
683      Scheduler.unstable_advanceTime(1);
684      expect(Scheduler).toHaveYielded(['A']);
685    });
686
687    it('cancels a delayed task', () => {
688      // Schedule several tasks with the same delay
689      const options = {delay: 100};
690
691      scheduleCallback(
692        NormalPriority,
693        () => Scheduler.unstable_yieldValue('A'),
694        options,
695      );
696      const taskB = scheduleCallback(
697        NormalPriority,
698        () => Scheduler.unstable_yieldValue('B'),
699        options,
700      );
701      const taskC = scheduleCallback(
702        NormalPriority,
703        () => Scheduler.unstable_yieldValue('C'),
704        options,
705      );
706
707      // Cancel B before its delay has elapsed
708      expect(Scheduler).toFlushAndYield([]);
709      cancelCallback(taskB);
710
711      // Cancel C after its delay has elapsed
712      Scheduler.unstable_advanceTime(500);
713      cancelCallback(taskC);
714
715      // Only A should flush
716      expect(Scheduler).toFlushAndYield(['A']);
717    });
718  });
719});
720
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)