terse-mock
Version:
Easy mock creation and automocking
48 lines (47 loc) • 1.94 kB
TypeScript
export declare const TM_ANY: unique symbol;
export interface IExternalMock {
create: () => any;
}
export type TOpt = {
automock: boolean;
collapseLongValues: boolean;
collapseThreshold: number;
externalMock?: IExternalMock;
exposeFunctionNames: boolean;
autoValuesPrefix: string;
defaultMockName: string;
quoteSymbol: string;
};
export type MockInfo = {
externalMock: any;
calls: any[];
callLog: string[];
};
export declare function tunmock(data: any): any;
export declare function tinfo(mockOrSpy?: any, pathInsideMock?: (mockProxy: any) => any): MockInfo;
export declare function treset(mock?: any): void;
export declare function tglobalopt(options?: Partial<TOpt>): TOpt;
export declare function tlocalopt(options?: Partial<TOpt>): Partial<TOpt>;
export type TInitCouple<T = void> = T extends void ? [(mockProxy: any) => any, any] : [(mockProxy: T) => any, any];
export type TInitObject<T = void> = T extends void ? {
[x: string]: Object | undefined | null;
} : Partial<T>;
export type TInit<T = void> = TInitObject<T> | TInitCouple<T> | (TInitObject<T> | TInitCouple<T>)[];
type TypeOrVoid<T> = T extends void ? void : T;
type InitializerArgType<T> = TInit<TypeOrVoid<T>>;
type NameOrInitializerArgType<T> = string | InitializerArgType<T>;
export declare function tmock<T = void>(nameOrInitializerArg?: NameOrInitializerArgType<T>, initializerArg?: InitializerArgType<T>): T extends void ? any : T;
export declare function tstub<T = void>(initializer: InitializerArgType<T>): T extends void ? any : T;
export declare function tset<T = any>(mockOrStub: any, initializer: InitializerArgType<T>): void;
declare const _default: {
ANY: symbol;
mock: typeof tmock;
stub: typeof tstub;
set: typeof tset;
reset: typeof treset;
unmock: typeof tunmock;
info: typeof tinfo;
globalopt: typeof tglobalopt;
localopt: typeof tlocalopt;
};
export default _default;