UNPKG

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