@@ -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 timers2
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,19 @@ class MockTimers {
513
526
this . #toggleEnableTimers( true ) ;
514
527
}
515
528
529
+ /**
530
+ * The `[SymbolDispose]` method is a custom method that can be used to dispose of the MockTimers instance.
531
+ * It internally calls the `reset` method to reset and disable the timers.
532
+ * It is intended for internal use and should not be called directly in most cases.
533
+ */
516
534
[ SymbolDispose ] ( ) {
517
535
this . reset ( ) ;
518
536
}
519
537
538
+ /**
539
+ * Resets MockTimers, disabling any enabled timers and clearing the execution queue.
540
+ * Does nothing if MockTimers are not enabled.
541
+ */
520
542
reset ( ) {
521
543
// Ignore if not enabled
522
544
if ( ! this . #isEnabled) return ;
@@ -531,6 +553,10 @@ class MockTimers {
531
553
}
532
554
}
533
555
556
+ /**
557
+ * Runs all scheduled timers until there are no more pending timers.
558
+ * @throws {ERR_INVALID_STATE } If MockTimers are not enabled.
559
+ */
534
560
runAll ( ) {
535
561
if ( ! this . #isEnabled) {
536
562
throw new ERR_INVALID_STATE (
0 commit comments