export type MockMetadataType = 'object' | 'array' | 'regexp' | 'function' | 'constant' | 'collection' | 'null' | 'undefined'; export type MockFunctionMetadataType = MockMetadataType; export type MockMetadata = { ref?: number; members?: Record>; mockImpl?: T; name?: string; refID?: number; type?: MetadataType; value?: T; length?: number; }; export type MockFunctionMetadata = MockMetadata; export type ClassLike = { new (...args: any): any; }; export type FunctionLike = (...args: any) => any; export type ConstructorLikeKeys = keyof { [K in keyof T as Required[K] extends ClassLike ? K : never]: T[K]; }; export type MethodLikeKeys = keyof { [K in keyof T as Required[K] extends FunctionLike ? K : never]: T[K]; }; export type PropertyLikeKeys = Exclude | MethodLikeKeys>; export type MockedClass = MockInstance<(...args: ConstructorParameters) => Mocked>> & MockedObject; export type MockedFunction = MockInstance & MockedObject; type MockedFunctionShallow = MockInstance & T; export type MockedObject = { [K in keyof T]: T[K] extends ClassLike ? MockedClass : T[K] extends FunctionLike ? MockedFunction : T[K] extends object ? MockedObject : T[K]; } & T; type MockedObjectShallow = { [K in keyof T]: T[K] extends ClassLike ? MockedClass : T[K] extends FunctionLike ? MockedFunctionShallow : T[K]; } & T; export type Mocked = T extends ClassLike ? MockedClass : T extends FunctionLike ? MockedFunction : T extends object ? MockedObject : T; export type MockedShallow = T extends ClassLike ? MockedClass : T extends FunctionLike ? MockedFunctionShallow : T extends object ? MockedObjectShallow : T; export type UnknownFunction = (...args: Array) => unknown; export type UnknownClass = { new (...args: Array): unknown; }; export type SpiedClass = MockInstance<(...args: ConstructorParameters) => InstanceType>; export type SpiedFunction = MockInstance<(...args: Parameters) => ReturnType>; export type SpiedGetter = MockInstance<() => T>; export type SpiedSetter = MockInstance<(arg: T) => void>; export type Spied = T extends ClassLike ? SpiedClass : T extends FunctionLike ? SpiedFunction : never; export interface SpyInstance extends MockInstance { } /** * All what the internal typings need is to be sure that we have any-function. * `FunctionLike` type ensures that and helps to constrain the type as well. * The default of `UnknownFunction` makes sure that `any`s do not leak to the * user side. For instance, calling `fn()` without implementation will return * a mock of `(...args: Array) => unknown` type. If implementation * is provided, its typings are inferred correctly. */ export interface Mock extends Function, MockInstance { new (...args: Parameters): ReturnType; (...args: Parameters): ReturnType; } type ResolveType = ReturnType extends PromiseLike ? U : never; type RejectType = ReturnType extends PromiseLike ? unknown : never; export interface MockInstance { _isMockFunction: true; _protoImpl: Function; getMockImplementation(): T | undefined; getMockName(): string; mock: MockFunctionState; mockClear(): this; mockReset(): this; mockRestore(): void; mockImplementation(fn: T): this; mockImplementationOnce(fn: T): this; withImplementation(fn: T, callback: () => Promise): Promise; withImplementation(fn: T, callback: () => void): void; mockName(name: string): this; mockReturnThis(): this; mockReturnValue(value: ReturnType): this; mockReturnValueOnce(value: ReturnType): this; mockResolvedValue(value: ResolveType): this; mockResolvedValueOnce(value: ResolveType): this; mockRejectedValue(value: RejectType): this; mockRejectedValueOnce(value: RejectType): this; } export interface Replaced { /** * Restore property to its original value known at the time of mocking. */ restore(): void; /** * Change the value of the property. */ replaceValue(value: T): this; } type MockFunctionResultIncomplete = { type: 'incomplete'; /** * Result of a single call to a mock function that has not yet completed. * This occurs if you test the result from within the mock function itself, * or from within a function that was called by the mock. */ value: undefined; }; type MockFunctionResultReturn = { type: 'return'; /** * Result of a single call to a mock function that returned. */ value: ReturnType; }; type MockFunctionResultThrow = { type: 'throw'; /** * Result of a single call to a mock function that threw. */ value: unknown; }; type MockFunctionResult = MockFunctionResultIncomplete | MockFunctionResultReturn | MockFunctionResultThrow; type MockFunctionState = { /** * List of the call arguments of all calls that have been made to the mock. */ calls: Array>; /** * List of all the object instances that have been instantiated from the mock. */ instances: Array>; /** * List of all the function contexts that have been applied to calls to the mock. */ contexts: Array>; /** * List of the call order indexes of the mock. Jest is indexing the order of * invocations of all mocks in a test file. The index is starting with `1`. */ invocationCallOrder: Array; /** * List of the call arguments of the last call that was made to the mock. * If the function was not called, it will return `undefined`. */ lastCall?: Parameters; /** * List of the results of all calls that have been made to the mock. */ results: Array>; }; export declare class ModuleMocker { private readonly _environmentGlobal; private _mockState; private _mockConfigRegistry; private _spyState; private _invocationCallCounter; /** * @see README.md * @param global Global object of the test environment, used to create * mocks */ constructor(global: typeof globalThis); private _getSlots; private _ensureMockConfig; private _ensureMockState; private _defaultMockConfig; private _defaultMockState; private _makeComponent; private _createMockFunction; private _generateMock; /** * Check whether the given property of an object has been already replaced. */ private _findReplacedProperty; /** * @see README.md * @param metadata Metadata for the mock in the schema returned by the * getMetadata method of this module. */ generateFromMetadata(metadata: MockMetadata): Mocked; /** * @see README.md * @param component The component for which to retrieve metadata. */ getMetadata(component: T, _refs?: Map): MockMetadata | null; isMockFunction(fn: MockInstance): fn is MockInstance; isMockFunction

, R>(fn: (...args: P) => R): fn is Mock<(...args: P) => R>; isMockFunction(fn: unknown): fn is Mock; fn(implementation?: T): Mock; spyOn, V extends Required[K], A extends 'get' | 'set'>(object: T, methodKey: K, accessType: A): A extends 'get' ? SpiedGetter : A extends 'set' ? SpiedSetter : never; spyOn | MethodLikeKeys, V extends Required[K]>(object: T, methodKey: K): V extends ClassLike | FunctionLike ? Spied : never; private _spyOnProperty; replaceProperty(object: T, propertyKey: K, value: T[K]): Replaced; clearAllMocks(): void; resetAllMocks(): void; restoreAllMocks(): void; private _typeOf; mocked(source: T, options?: { shallow: false; }): Mocked; mocked(source: T, options: { shallow: true; }): MockedShallow; } export declare const fn: (implementation?: T | undefined) => Mock; export declare const spyOn: { [K] extends ClassLike ? K : never]: T[K]; } | keyof { [K_1 in keyof T as Required[K_1] extends FunctionLike ? K_1 : never]: T[K_1]; }>, V extends Required[K_2], A extends "get" | "set">(object: T, methodKey: K_2, accessType: A): A extends "get" ? SpiedGetter : A extends "set" ? SpiedSetter : never; [K_3] extends ClassLike ? K_3 : never]: T_1[K_3]; } | keyof { [K_4 in keyof T_1 as Required[K_4] extends FunctionLike ? K_4 : never]: T_1[K_4]; }, V_1 extends Required[K_5]>(object: T_1, methodKey: K_5): V_1 extends ClassLike | FunctionLike ? Spied : never; }; export declare const mocked: { (source: T, options?: { shallow: false; }): Mocked; (source: T_1, options: { shallow: true; }): MockedShallow; }; export declare const replaceProperty: (object: T, propertyKey: K, value: T[K]) => Replaced; export {}; //# sourceMappingURL=jest-mock.d.ts.map