/** * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ export declare type MockFunctionMetadataType = 'object' | 'array' | 'regexp' | 'function' | 'constant' | 'collection' | 'null' | 'undefined'; export declare type MockFunctionMetadata, Type = MockFunctionMetadataType> = { ref?: number; members?: Record>; mockImpl?: (...args: Y) => T; name?: string; refID?: number; type?: Type; value?: T; length?: number; }; export interface Mock = Array> extends Function, MockInstance { new (...args: Y): T; (...args: Y): T; } export interface SpyInstance> extends MockInstance { } export interface MockInstance> { _isMockFunction: true; _protoImpl: Function; getMockName(): string; getMockImplementation(): Function | undefined; mock: MockFunctionState; mockClear(): this; mockReset(): this; mockRestore(): void; mockImplementation(fn: (...args: Y) => T): this; mockImplementation(fn: () => Promise): this; mockImplementationOnce(fn: (...args: Y) => T): this; mockImplementationOnce(fn: () => Promise): this; mockName(name: string): this; mockReturnThis(): this; mockReturnValue(value: T): this; mockReturnValueOnce(value: T): this; mockResolvedValue(value: Unpromisify): this; mockResolvedValueOnce(value: Unpromisify): this; mockRejectedValue(value: unknown): this; mockRejectedValueOnce(value: unknown): this; } declare type Unpromisify = T extends Promise ? R : never; /** * Possible types of a MockFunctionResult. * 'return': The call completed by returning normally. * 'throw': The call completed by throwing a value. * 'incomplete': The call has not completed yet. This is possible if you read * the mock function result from within the mock function itself * (or a function called by the mock function). */ declare type MockFunctionResultType = 'return' | 'throw' | 'incomplete'; /** * Represents the result of a single call to a mock function. */ declare type MockFunctionResult = { /** * Indicates how the call completed. */ type: MockFunctionResultType; /** * The value that was either thrown or returned by the function. * Undefined when type === 'incomplete'. */ value: unknown; }; declare type MockFunctionState> = { calls: Array; instances: Array; invocationCallOrder: Array; /** * List of results of calls to the mock function. */ results: Array; }; declare type NonFunctionPropertyNames = { [K in keyof T]: T[K] extends (...args: Array) => any ? never : K; }[keyof T] & string; declare type FunctionPropertyNames = { [K in keyof T]: T[K] extends (...args: Array) => any ? K : never; }[keyof T] & string; export declare class ModuleMocker { private _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; /** * @see README.md * @param _metadata Metadata for the mock in the schema returned by the * getMetadata method of this module. */ generateFromMetadata>(_metadata: MockFunctionMetadata): Mock; /** * @see README.md * @param component The component for which to retrieve metadata. */ getMetadata>(component: T, _refs?: Map): MockFunctionMetadata | null; isMockFunction(fn: unknown): fn is Mock; fn>(implementation?: (...args: Y) => T): Mock; spyOn>(object: T, methodName: M, accessType: 'get'): SpyInstance; spyOn>(object: T, methodName: M, accessType: 'set'): SpyInstance; spyOn>(object: T, methodName: M): T[M] extends (...args: Array) => any ? SpyInstance, Parameters> : never; private _spyOnProperty; clearAllMocks(): void; resetAllMocks(): void; restoreAllMocks(): void; private _typeOf; } export declare const fn: (implementation?: ((...args: Y) => T) | undefined) => Mock; export declare const spyOn: { >(object: T, methodName: M, accessType: 'get'): SpyInstance; >(object: T_2, methodName: M_2, accessType: 'set'): SpyInstance; >(object: T_4, methodName: M_4): T_4[M_4] extends (...args: Array) => any ? SpyInstance, Parameters> : never; }; export {};