UNPKG

@hirez_io/auto-spies-core

Version:

Create automatic spies from classes in tests, also for promises and observables, used as a common code for jasmine-auto-spies and jest-auto-spies

29 lines (28 loc) 1.47 kB
import { Func, WrappedValueConfigPerCall, ValueConfigPerCall, ValueConfig } from '.'; import { Subject } from 'rxjs'; import { ArgsMap } from './args-map'; export interface CalledWithObject { wasConfigured: boolean; argsToValuesMap: ArgsMap; resolveWith?: (value?: any) => void; resolveWithPerCall?<T = any>(valuesPerCall?: ValueConfigPerCall<T>[]): void; rejectWith?: (value?: any) => void; nextWith?(value?: any): void; nextOneTimeWith?(value?: any): void; nextWithValues?<T = any>(valuesConfigs: ValueConfig<T>[]): void; nextWithPerCall?<T = any>(valuesPerCall?: ValueConfigPerCall<T>[]): Subject<T>[]; throwWith?(value: any): void; complete?(): void; returnSubject?<R = any>(): Subject<R>; } export interface ReturnValueContainer { value: any; _isRejectedPromise?: boolean; valuesPerCalls?: WrappedValueConfigPerCall[]; } export type CalledWithFrameworkMethodsDecorator<FrameworkSpecificType> = (calledWithObject: CalledWithObject, calledWithArgs: any[]) => CalledWithObject & FrameworkSpecificType; export type FunctionSpyFactory = (functionName: string, spyFunctionImplementation: Func) => { functionSpy: any; objectToAddSpyMethodsTo: any; }; export declare function createFunctionAutoSpy<ReturnType, LibSpecificType>(functionName: string, addFrameworkMethodsToCalledWithObject: CalledWithFrameworkMethodsDecorator<LibSpecificType>, frameworkFunctionSpyFactory: FunctionSpyFactory): ReturnType;