/** * This file is part of spy4js which is released under MIT license. * * The LICENSE file can be found in the root directory of this project. * */ import { configure, configureAll } from './config'; import { type Mockable } from './mock'; import { Symbols } from './symbols'; import { COMPARE, MAPPER, type MessageOrError, type OptionalMessageOrError } from './utils'; type SpyInstanceConfig = { useOwnEquals: boolean; persistent: boolean; }; type FlatAwaited = TVal extends PromiseLike ? TAwaited : never; export type SpyInstance any = (...args: any) => any> = TFunc & { configure: (config: Partial) => SpyInstance; calls: (...funcs: TFunc[]) => SpyInstance; returns: (...args: ReturnType[]) => SpyInstance; resolves: FlatAwaited> extends never ? never : (...args: FlatAwaited>[]) => SpyInstance; rejects: FlatAwaited> extends never ? never : (...msgOrErrors: OptionalMessageOrError[]) => SpyInstance; throws: (msgOrError?: MessageOrError) => SpyInstance; reset: () => SpyInstance; restore: () => SpyInstance; transparent: () => SpyInstance; transparentAfter: (callCount: number) => SpyInstance; addSnapshotSerializer: (serialize: string | ((...args: any[]) => string)) => SpyInstance; wasCalled: (callCount?: number) => void; hasCallHistory: (...callHistory: Array) => void; wasNotCalled: () => void; wasCalledWith: (...args: any[]) => void; wasNotCalledWith: (...args: any[]) => void; getAllCallArguments: () => Array; getCallArguments: (callNr?: number) => any[]; getCallArgument: (callNr?: number, argNr?: number) => any; getLatestCallArgument: (argNr?: number) => any; getProps: () => any; hasProps: (props: any) => void; getCallCount: () => number; showCallArguments: (additionalInformation?: (string | undefined)[]) => string; [Symbols.name]: string; [Symbols.snap]: string; [Symbols.snapSerializer]?: (...args: any[]) => string; [Symbols.calls]: { args: any[]; order: number; }[]; [Symbols.index]: number; [Symbols.isSpy]: boolean; [Symbols.func]: (...args: any[]) => any; [Symbols.config]: SpyInstanceConfig; [Symbols.onRestore]?: () => void; }; type ISpy = { (name?: string): SpyInstance; configure: typeof configure; setup: typeof configureAll; IGNORE: symbol; COMPARE: typeof COMPARE; MAPPER: typeof MAPPER; on(obj: T, methodName: K): SpyInstance; mock(obj: T, ...methodNames: K[]): { [P in K]: SpyInstance; }; mockReactComponents(obj: T, ...methodNames: K[]): { [P in K]: SpyInstance; }; restoreAll(): void; resetAll(): void; }; /** * This constructor does instantiate a Spy * object. * * This spy is callable. * It does inherit all Spy specific methods below. * It holds additional (private) fields: * _name:string -> Will be displayed in all displayed * error messages. * _isSpy:boolean -> Always true for spies. * _func:Function -> The internal function, that will * actually we called, when calling * the spy. * _calls:Array<{arguments:Array}> * -> Stores the arguments with whom the spy was called. * Each call adds another entry in the calls array. * _config = {useOwnEquals: boolean} -> internal spy config. * * * @param name -> the identifier of the spy. * Useful for debugging issues. */ declare const Spy: ISpy; export { Spy };