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