Skip to content

Commit 5949ae0

Browse files
ErickWendeltargos
authored andcommitted
test_runner: add jsdocs to MockTimers
Signed-off-by: Erick Wendel <[email protected]> PR-URL: #49476 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
1 parent 429846f commit 5949ae0

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/internal/test_runner/mock/mock_timers.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,13 @@ class MockTimers {
454454
);
455455
}
456456

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+
*/
457464
tick(time = 1) {
458465
if (!this.#isEnabled) {
459466
throw new ERR_INVALID_STATE(
@@ -487,6 +494,12 @@ class MockTimers {
487494
}
488495
}
489496

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+
*/
490503
enable(timers = SUPPORTED_TIMERS) {
491504
if (this.#isEnabled) {
492505
throw new ERR_INVALID_STATE(
@@ -512,10 +525,17 @@ class MockTimers {
512525
this.#toggleEnableTimers(true);
513526
}
514527

528+
/**
529+
* An alias for `this.reset()`, allowing the disposal of the `MockTimers` instance.
530+
*/
515531
[SymbolDispose]() {
516532
this.reset();
517533
}
518534

535+
/**
536+
* Resets MockTimers, disabling any enabled timers and clearing the execution queue.
537+
* Does nothing if MockTimers are not enabled.
538+
*/
519539
reset() {
520540
// Ignore if not enabled
521541
if (!this.#isEnabled) return;
@@ -530,6 +550,10 @@ class MockTimers {
530550
}
531551
}
532552

553+
/**
554+
* Runs all scheduled timers until there are no more pending timers.
555+
* @throws {ERR_INVALID_STATE} If MockTimers are not enabled.
556+
*/
533557
runAll() {
534558
if (!this.#isEnabled) {
535559
throw new ERR_INVALID_STATE(

0 commit comments

Comments
 (0)