GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test_runner: add jsdocs to MockTimers · nodejs/node@5949ae0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/test_runner/mock
    • mock_timers.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/test_runner/mock/mock_timers.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/mock/mock_timers.js
+24Lines 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 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.