UNPKG

2.22 kBTypeScriptView Raw
1/// <reference types="jest" />
2import { MatchersOrLiterals } from './Matchers';
3import { DeepPartial } from 'ts-essentials';
4type ProxiedProperty = string | number | symbol;
5export interface GlobalConfig {
6 ignoreProps?: ProxiedProperty[];
7}
8export declare const JestMockExtended: {
9 DEFAULT_CONFIG: GlobalConfig;
10 configure: (config: GlobalConfig) => void;
11 resetConfig: () => void;
12};
13export interface CalledWithMock<T, Y extends any[]> extends jest.Mock<T, Y> {
14 calledWith: (...args: Y | MatchersOrLiterals<Y>) => jest.Mock<T, Y>;
15}
16export type _MockProxy<T> = {
17 [K in keyof T]: T[K] extends (...args: infer A) => infer B ? T[K] & CalledWithMock<B, A> : T[K];
18};
19export type MockProxy<T> = _MockProxy<T> & T;
20export type _DeepMockProxy<T> = {
21 [K in keyof T]: T[K] extends (...args: infer A) => infer B ? T[K] & CalledWithMock<B, A> : T[K] & _DeepMockProxy<T[K]>;
22};
23export type DeepMockProxy<T> = _DeepMockProxy<T> & T;
24export type _DeepMockProxyWithFuncPropSupport<T> = {
25 [K in keyof T]: T[K] extends (...args: infer A) => infer B ? CalledWithMock<B, A> & DeepMockProxy<T[K]> : DeepMockProxy<T[K]>;
26};
27export type DeepMockProxyWithFuncPropSupport<T> = _DeepMockProxyWithFuncPropSupport<T> & T;
28export interface MockOpts {
29 deep?: boolean;
30 fallbackMockImplementation?: (...args: any[]) => any;
31}
32export declare const mockClear: (mock: MockProxy<any>) => any;
33export declare const mockReset: (mock: MockProxy<any>) => any;
34export declare function mockDeep<T>(opts: {
35 funcPropSupport?: true;
36 fallbackMockImplementation?: MockOpts['fallbackMockImplementation'];
37}, mockImplementation?: DeepPartial<T>): DeepMockProxyWithFuncPropSupport<T>;
38export declare function mockDeep<T>(mockImplementation?: DeepPartial<T>): DeepMockProxy<T>;
39declare const mock: <T, MockedReturn extends _MockProxy<T> & T = _MockProxy<T> & T>(mockImplementation?: DeepPartial<T>, opts?: MockOpts) => MockedReturn;
40export declare const mockFn: <T extends Function, A extends any[] = T extends (...args: infer AReal) => any ? AReal : any[], R = T extends (...args: any) => infer RReal ? RReal : any>() => CalledWithMock<R, A> & T;
41export declare const stub: <T extends object>() => T;
42export default mock;