UNPKG

@hexancore/mocker

Version:

Simple and magical mocks for TypeScript, works with jest and vitest

37 lines (36 loc) 1.18 kB
import { Mocker } from './Mocker'; import { Ctor } from './util'; export type WrapPropsWithMocker<T extends Record<string, any>> = { [P in keyof T]: Mocker<T[P]>; }; export type MST<T extends Record<string, any>> = WrapPropsWithMocker<T> & Mockers<T>; /** * Manages a group of defined mocks in a more efficient way of writing test code */ export declare class Mockers<T> { constructor(mocks: T); /** * Wraps * @param mocks * @returns */ static wrap<T>(mocks: T): MST<T>; /** * Return fresh instance of mocks manager(usually used in beforeEach) * @returns */ xFresh(): MST<T>; /** * Create object of given class constructor with injected mocks and other non Mock args; * @param ctr * @param nonMockArgs * @returns */ xNewInject<T>(ctr: Ctor<T>, nonMockArgs?: Array<any> | any): T; xConstructorArgs<T extends abstract new (...args: any) => any>(ctr: T, nonMockArgs?: Array<any> | any): ConstructorParameters<T>; /** * Checks expections of all managed mocks(usually used in afterEach) */ xCheckExpections(): void; } export declare const mocks: <T>(mocks: T) => MST<T>;