UNPKG

mockzilla

Version:

A mocking toolkit leveraging the power of TypeScript to enhance your jest experience.

43 lines (42 loc) 1.87 kB
export interface MockzillaExpectation { stack: string; spy?: (...args: any[]) => any; args?: any[]; returns?: any; throws?: Error; } export interface MockzillaTimes { times: (count: number) => void; } export declare type MockzillaAsyncFunction<T> = { andResolve: T; andReject: (error: Error) => MockzillaTimes; times: (count: number) => void; }; export declare type MockzillaSyncFunction<T> = { andReturn: T; andThrow: (error: Error) => MockzillaTimes; times: (count: number) => void; }; export declare type MockzillaFunction<T extends (...args: any[]) => any> = ReturnType<T> extends Promise<infer TP> ? TP extends boolean ? MockzillaAsyncFunction<(result: boolean) => MockzillaTimes> : TP extends void ? MockzillaAsyncFunction<() => MockzillaTimes> : MockzillaAsyncFunction<(result: TP) => MockzillaTimes> : ReturnType<T> extends void ? MockzillaSyncFunction<() => MockzillaTimes> : MockzillaSyncFunction<(result: ReturnType<T>) => MockzillaTimes>; export declare type MockzillaProperty<T> = { mock: (value: T) => void; mockAllow: () => void; mockAllowMethod: () => void; mockPath: string; }; export declare type MockzillaDeep<T> = { [TKey in keyof T]: MockzillaDeep<T[TKey]>; } & MockzillaProperty<T> & (T extends (...args: any[]) => any ? { spy: (fn: T) => MockzillaTimes; expect: ((...args: Parameters<T>) => MockzillaFunction<T>) & MockzillaFunction<T>; getMockCalls: () => Array<Parameters<T>>; } : unknown); export declare type MockzillaAssimilated<T> = T extends (...args: any[]) => any ? { spy: (fn: T) => MockzillaTimes; expect: ((...args: Parameters<T>) => MockzillaFunction<T>) & MockzillaFunction<T>; getMockCalls: () => Array<Parameters<T>>; } : unknown; export declare type MockzillaAssimilatedMap<T> = { [TKey in keyof T]: MockzillaAssimilated<T[TKey]>; };