@@ -454,6 +454,13 @@ class MockTimers {
454
454
) ;
455
455
}
456
456
457
+ /**
458
+ * Advances the virtual time of MockTimers by the specified duration (in milliseconds).
459
+ * This method simulates the passage of time and triggers any scheduled timers that are due.
460
+ * @param {number } [time=1] - The amount of time (in milliseconds) to advance the virtual time.
461
+ * @throws {ERR_INVALID_STATE } If MockTimers are not enabled.
462
+ * @throws {ERR_INVALID_ARG_VALUE } If a negative time value is provided.
463
+ */
457
464
tick ( time = 1 ) {
458
465
if ( ! this . #isEnabled) {
459
466
throw new ERR_INVALID_STATE (
@@ -487,6 +494,12 @@ class MockTimers {
487
494
}
488
495
}
489
496
497
+ /**
498
+ * Enables MockTimers for the specified timers.
499
+ * @param {string[] } timers - An array of timer types to enable, e.g., ['setTimeout', 'setInterval'].
500
+ * @throws {ERR_INVALID_STATE } If MockTimers are already enabled.
501
+ * @throws {ERR_INVALID_ARG_VALUE } If an unsupported timer type is specified.
502
+ */
490
503
enable ( timers = SUPPORTED_TIMERS ) {
491
504
if ( this . #isEnabled) {
492
505
throw new ERR_INVALID_STATE (
@@ -512,10 +525,17 @@ class MockTimers {
512
525
this . #toggleEnableTimers( true ) ;
513
526
}
514
527
528
+ /**
529
+ * An alias for `this.reset()`, allowing the disposal of the `MockTimers` instance.
530
+ */
515
531
[ SymbolDispose ] ( ) {
516
532
this . reset ( ) ;
517
533
}
518
534
535
+ /**
536
+ * Resets MockTimers, disabling any enabled timers and clearing the execution queue.
537
+ * Does nothing if MockTimers are not enabled.
538
+ */
519
539
reset ( ) {
520
540
// Ignore if not enabled
521
541
if ( ! this . #isEnabled) return ;
@@ -530,6 +550,10 @@ class MockTimers {
530
550
}
531
551
}
532
552
553
+ /**
554
+ * Runs all scheduled timers until there are no more pending timers.
555
+ * @throws {ERR_INVALID_STATE } If MockTimers are not enabled.
556
+ */
533
557
runAll ( ) {
534
558
if ( ! this . #isEnabled) {
535
559
throw new ERR_INVALID_STATE (
0 commit comments