@hexancore/mocker
Version:
Simple and magical mocks for TypeScript, works with jest and vitest
20 lines (19 loc) • 944 B
TypeScript
export interface MockFn<TArgs extends any[] = any[], TReturns = any> {
getMockName(): string;
mockName(n: string): this;
mockClear(): this;
mockReset(): this;
mockRestore(): void;
getMockImplementation(): ((...args: TArgs) => TReturns) | undefined;
mockImplementation(fn: ((...args: TArgs) => TReturns) | (() => Promise<TReturns>)): this;
mockImplementationOnce(fn: ((...args: TArgs) => TReturns) | (() => Promise<TReturns>)): this;
withImplementation<T>(fn: ((...args: TArgs) => TReturns), cb: () => T): T extends Promise<unknown> ? Promise<this> : this;
mockReturnThis(): this;
mockReturnValue(obj: TReturns): this;
mockReturnValueOnce(obj: TReturns): this;
mockResolvedValue(obj: Awaited<TReturns>): this;
mockResolvedValueOnce(obj: Awaited<TReturns>): this;
mockRejectedValue(obj: any): this;
mockRejectedValueOnce(obj: any): this;
}
export type MockFnFactory = () => MockFn;