Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions types/node/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,17 @@ declare module "node:test" {
* @since v19.1.0, v18.13.0
*/
restoreAll(): void;
/**
* This function is used to mock the exports of ECMAScript modules,
* CommonJS modules, and Node.js builtin modules. Any references to
* the original module prior to mocking are not impacted
* @since v22.3.0
*/
module(speficier: string, options?: {
cache?: boolean;
defaultExport?: any;
namedExports?: object;
}): { restore: () => void };
timers: MockTimers;
}
const mock: MockTracker;
Expand Down
16 changes: 16 additions & 0 deletions types/node/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,22 @@ test("mocks a counting function", (t) => {
const fn = t.mock.fn(addOne, addTwo, { times: 2 });
// $ExpectType number
fn();

const mock = t.mock.module("node:readline", {
namedExports: {
fn() {
return 42;
},
},
defaultExport: {
foo() {
return "bar";
},
},
cache: true,
});
// $ExpectType void
mock.restore();
});

test("spies on an object method", (t) => {
Expand Down