/**
* 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.
*/
///
declare type Global = NodeJS.Global;
declare namespace JestMock {
type ModuleMocker = ModuleMockerClass;
type MockFunctionMetadataType = 'object' | 'array' | 'regexp' | 'function' | 'constant' | 'collection' | 'null' | 'undefined';
type MockFunctionMetadata, Type = MockFunctionMetadataType> = {
ref?: number;
members?: Record>;
mockImpl?: (...args: Y) => T;
name?: string;
refID?: number;
type?: Type;
value?: T;
length?: number;
};
}
/**
* 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;
interface Mock = Array> extends Function, MockInstance {
new (...args: Y): T;
(...args: Y): T;
}
interface SpyInstance> extends MockInstance {
}
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: T): this;
mockResolvedValueOnce(value: T): this;
mockRejectedValue(value: T): this;
mockRejectedValueOnce(value: T): this;
}
declare class ModuleMockerClass {
private _environmentGlobal;
private _mockState;
private _mockConfigRegistry;
private _spyState;
private _invocationCallCounter;
ModuleMocker: typeof ModuleMockerClass;
/**
* @see README.md
* @param global Global object of the test environment, used to create
* mocks
*/
constructor(global: Global);
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: JestMock.MockFunctionMetadata): Mock;
/**
* @see README.md
* @param component The component for which to retrieve metadata.
*/
getMetadata>(component: T, _refs?: Map): JestMock.MockFunctionMetadata | null;
isMockFunction(fn: any): 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;
}
declare const JestMock: ModuleMockerClass;
export = JestMock;