import { DISPOSE_SYMBOL } from './symbol.js'; export type FunctionLike = (...args: any[]) => any; export interface StubCall { readonly args: TArgs; readonly returnValue?: TReturn; readonly thisValue: unknown; } /** * Represents a single stubbed function */ export declare class Stub { [DISPOSE_SYMBOL]: () => void; /** * Wrapped function */ handler: T; /** * Function to be called when stub is restored */ restoreCallback?: () => void; /** * Original function */ original: T; protected _calls: Set, ReturnType>>; protected _returnValue?: ReturnType; protected _returnFunction?: T; /** * Whether or not this stub has been called */ get called(): boolean; /** * List of all calls this stub has received */ get calls(): ReadonlySet, ReturnType>>; /** * Retrieves an individual call * @param index Index of the call to retrieve * @return Call at the specified index */ getCall(index: number): StubCall, ReturnType>; /** * Retrieves the first call * @return Call object */ get firstCall(): StubCall, ReturnType> | undefined; /** * Retrieves the last call * @return Call object */ get lastCall(): StubCall, ReturnType> | undefined; /** * Number of times this stub has been called */ get callCount(): number; /** * Constructor * @param fn Function being stubbed */ constructor(fn: T); /** * Processes an individual call to this stub * @param thisValue Context of the call (`this`) * @param args Arguments passed when being called * @return Return value of this call */ protected _handleCall(thisValue: unknown, args: Parameters): ReturnType | undefined; /** * Specifies the value this stub should return * @param val Value to return * @return {this} */ returns(val: ReturnType): this; /** * Specifies the value this stub should return, but as a promise * @param val Value to return * @return {this} */ resolves(val: Awaited>): this; /** * Specifies a function to call to retrieve the return value of this * stub * @param fn Function to call * @return {this} */ callsFake(fn: (...args: Parameters) => ReturnType): this; /** * Enables pass-through, in that the original function is called when * this stub is called. * @return {this} */ passThrough(): this; /** * Resets call state (e.g. call count, calls, etc.) */ reset(): void; /** * Restores this stub. * This behaviour differs depending on what created the stub. */ restore(): void; /** * Asserts that the stub was called with a set of arguments * @param args Arguments to assert for * @return Whether they were passed or not */ calledWith(...args: Parameters): boolean; /** * Asserts that the stub returned a given value * @param val Value to check for * @return Whether the value was ever returned or not */ returned(val: ReturnType): boolean; } export type StubbedFunction = T extends FunctionLike ? T : FunctionLike; /** * Stubs a method of a given object. * @param obj Object the method belongs to * @param method Method name to stub * @return Stubbed method */ export declare function stubMethod(obj: TObj, method: TKey): Stub>; /** * Spies a method of a given object. * @param obj Object the method belongs to * @param method Method name to spy * @return Stubbed method */ export declare function spyMethod(obj: TObj, method: TKey): Stub>; /** * Stubs a given function. * @param fn Function to stub * @return Stubbed function */ export declare function stub(fn: T): Stub; /** * Creates an anonymous spy. * @return Anonymous stub */ export declare function spy(): Stub; /** * Restores all tracked stubs at once. */ export declare function restore(): void;