Skip to content

Commit 577ebf1

Browse files
committed
1 parent e6b9bf3 commit 577ebf1

6 files changed

Lines changed: 42 additions & 3 deletions

File tree

types/node/node-tests/test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
todo,
2121
} from "node:test";
2222
import { dot, junit, lcov, spec, tap, TestEvent } from "node:test/reporters";
23+
import { URL } from "node:url";
2324

2425
// top-level export
2526
test satisfies typeof import("node:test");
@@ -795,6 +796,7 @@ test("mocks a setter", (t) => {
795796
});
796797

797798
test("mocks a module", (t) => {
799+
// module specifier as a string
798800
// $ExpectType MockModuleContext
799801
const mock = t.mock.module("node:readline", {
800802
namedExports: {
@@ -811,6 +813,16 @@ test("mocks a module", (t) => {
811813
});
812814
// $ExpectType void
813815
mock.restore();
816+
817+
// module specifier as a URL
818+
// $ExpectType MockModuleContext
819+
t.mock.module(new URL("someUrl"), {
820+
namedExports: {
821+
fn() {
822+
return 42;
823+
},
824+
},
825+
});
814826
});
815827

816828
test("mocks a property", (t) => {

types/node/test.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ declare module "node:test" {
8282
import { AssertMethodNames } from "node:assert";
8383
import { Readable, ReadableEventMap } from "node:stream";
8484
import { TestEvent } from "node:test/reporters";
85+
import { URL } from "node:url";
8586
import TestFn = test.TestFn;
8687
import TestOptions = test.TestOptions;
8788
/**
@@ -1692,7 +1693,7 @@ declare module "node:test" {
16921693
* @param specifier A string identifying the module to mock.
16931694
* @param options Optional configuration options for the mock module.
16941695
*/
1695-
module(specifier: string, options?: MockModuleOptions): MockModuleContext;
1696+
module(specifier: string | URL, options?: MockModuleOptions): MockModuleContext;
16961697
/**
16971698
* Creates a mock for a property value on an object. This allows you to track and control access to a specific property,
16981699
* including how many times it is read (getter) or written (setter), and to restore the original value after mocking.

types/node/v22/test.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
declare module "node:test" {
8282
import { AssertMethodNames } from "node:assert";
8383
import { Readable } from "node:stream";
84+
import { URL } from "node:url";
8485
import TestFn = test.TestFn;
8586
import TestOptions = test.TestOptions;
8687
/**
@@ -1638,7 +1639,7 @@ declare module "node:test" {
16381639
* @param specifier A string identifying the module to mock.
16391640
* @param options Optional configuration options for the mock module.
16401641
*/
1641-
module(specifier: string, options?: MockModuleOptions): MockModuleContext;
1642+
module(specifier: string | URL, options?: MockModuleOptions): MockModuleContext;
16421643
/**
16431644
* This function restores the default behavior of all mocks that were previously
16441645
* created by this `MockTracker` and disassociates the mocks from the `MockTracker` instance. Once disassociated, the mocks can still be used, but the `MockTracker` instance can no longer be

types/node/v22/test/test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
todo,
2121
} from "node:test";
2222
import { dot, junit, lcov, spec, tap, TestEvent } from "node:test/reporters";
23+
import { URL } from "node:url";
2324

2425
// top-level export
2526
test satisfies typeof import("node:test");
@@ -791,6 +792,7 @@ test("mocks a setter", (t) => {
791792
});
792793

793794
test("mocks a module", (t) => {
795+
// module specifier as a string
794796
// $ExpectType MockModuleContext
795797
const mock = t.mock.module("node:readline", {
796798
namedExports: {
@@ -807,6 +809,16 @@ test("mocks a module", (t) => {
807809
});
808810
// $ExpectType void
809811
mock.restore();
812+
813+
// module specifier as a URL
814+
// $ExpectType MockModuleContext
815+
t.mock.module(new URL("someUrl"), {
816+
namedExports: {
817+
fn() {
818+
return 42;
819+
},
820+
},
821+
});
810822
});
811823

812824
// @ts-expect-error

types/node/v24/test.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
declare module "node:test" {
8282
import { AssertMethodNames } from "node:assert";
8383
import { Readable } from "node:stream";
84+
import { URL } from "node:url";
8485
import TestFn = test.TestFn;
8586
import TestOptions = test.TestOptions;
8687
/**
@@ -1711,7 +1712,7 @@ declare module "node:test" {
17111712
* @param specifier A string identifying the module to mock.
17121713
* @param options Optional configuration options for the mock module.
17131714
*/
1714-
module(specifier: string, options?: MockModuleOptions): MockModuleContext;
1715+
module(specifier: string | URL, options?: MockModuleOptions): MockModuleContext;
17151716
/**
17161717
* Creates a mock for a property value on an object. This allows you to track and control access to a specific property,
17171718
* including how many times it is read (getter) or written (setter), and to restore the original value after mocking.

types/node/v24/test/test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
todo,
2121
} from "node:test";
2222
import { dot, junit, lcov, spec, tap, TestEvent } from "node:test/reporters";
23+
import { URL } from "node:url";
2324

2425
// top-level export
2526
test satisfies typeof import("node:test");
@@ -795,6 +796,7 @@ test("mocks a setter", (t) => {
795796
});
796797

797798
test("mocks a module", (t) => {
799+
// module specifier as a string
798800
// $ExpectType MockModuleContext
799801
const mock = t.mock.module("node:readline", {
800802
namedExports: {
@@ -811,6 +813,16 @@ test("mocks a module", (t) => {
811813
});
812814
// $ExpectType void
813815
mock.restore();
816+
817+
// module specifier as a URL
818+
// $ExpectType MockModuleContext
819+
t.mock.module(new URL("someUrl"), {
820+
namedExports: {
821+
fn() {
822+
return 42;
823+
},
824+
},
825+
});
814826
});
815827

816828
test("mocks a property", (t) => {

0 commit comments

Comments
 (0)