Skip to content
Closed
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
37 changes: 22 additions & 15 deletions types/node/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,25 +790,32 @@ declare module "node:test" {
method<
MockedObject extends object,
MethodName extends FunctionPropertyNames<MockedObject>,
Implementation extends Function,
Implementation extends MockedObject[MethodName] extends Function ? MockedObject[MethodName] : never,
>(
object: MockedObject,
methodName: MethodName,
implementation: Implementation,
options?: MockFunctionOptions,
): MockedObject[MethodName] extends Function ? Mock<MockedObject[MethodName] | Implementation>
: never;
method<MockedObject extends object>(
): Mock<Implementation>;
method<
MockedObject extends object,
MethodName extends keyof MockedObject,
Implementation extends MockedObject[MethodName] extends Function ? MockedObject[MethodName] : Function,
>(
object: MockedObject,
methodName: keyof MockedObject,
methodName: MethodName,
options: MockMethodOptions,
): Mock<Function>;
method<MockedObject extends object>(
): Mock<Implementation>;
method<
MockedObject extends object,
MethodName extends keyof MockedObject,
Implementation extends MockedObject[MethodName] extends Function ? MockedObject[MethodName] : Function,
>(
object: MockedObject,
methodName: keyof MockedObject,
implementation: Function,
options: MockMethodOptions,
): Mock<Function>;
): Mock<Implementation>;

/**
* This function is syntax sugar for `MockTracker.method` with `options.getter`set to `true`.
Expand All @@ -825,13 +832,13 @@ declare module "node:test" {
getter<
MockedObject extends object,
MethodName extends keyof MockedObject,
Implementation extends Function,
Implementation extends () => MockedObject[MethodName],
>(
object: MockedObject,
methodName: MethodName,
implementation?: Implementation,
options?: MockFunctionOptions,
): Mock<(() => MockedObject[MethodName]) | Implementation>;
): Mock<Implementation>;
/**
* This function is syntax sugar for `MockTracker.method` with `options.setter`set to `true`.
* @since v19.3.0, v18.13.0
Expand All @@ -847,13 +854,13 @@ declare module "node:test" {
setter<
MockedObject extends object,
MethodName extends keyof MockedObject,
Implementation extends Function,
Implementation extends (value: MockedObject[MethodName]) => void,
>(
object: MockedObject,
methodName: MethodName,
implementation?: Implementation,
options?: MockFunctionOptions,
): Mock<((value: MockedObject[MethodName]) => void) | Implementation>;
): Mock<Implementation>;
/**
* This function restores the default behavior of all mocks that were previously
* 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
Expand Down Expand Up @@ -962,7 +969,7 @@ declare module "node:test" {
* @since v19.1.0, v18.13.0
* @param implementation The function to be used as the mock's new implementation.
*/
mockImplementation(implementation: Function): void;
mockImplementation(implementation: F): void;
/**
* This function is used to change the behavior of an existing mock for a single
* invocation. Once invocation `onCall` has occurred, the mock will revert to
Expand Down Expand Up @@ -997,9 +1004,9 @@ declare module "node:test" {
* ```
* @since v19.1.0, v18.13.0
* @param implementation The function to be used as the mock's implementation for the invocation number specified by `onCall`.
* @param onCall The invocation number that will use `implementation`. If the specified invocation has already occurred then an exception is thrown.
* @param [onCall=The number of the next invocation.] The invocation number that will use `implementation`. If the specified invocation has already occurred then an exception is thrown.
*/
mockImplementationOnce(implementation: Function, onCall?: number): void;
mockImplementationOnce(implementation: F, onCall?: number): void;
/**
* Resets the call history of the mock function.
* @since v19.3.0, v18.13.0
Expand Down