@johanblumenberg/ts-mockito
Version:
Mocking library for TypeScript
46 lines (45 loc) • 2.01 kB
TypeScript
import { MethodToStub } from "./MethodToStub";
import { MockInvocation } from "./stub/CallFunctionMethodStub";
export interface SyncMethodStubSetter<T> {
thenReturn(head: T, ...tail: T[]): this;
thenReturnOnce(value: T): this;
thenThrow(head: Error, ...tail: Error[]): this;
thenThrowOnce(error: Error): this;
thenCall(func: (this: MockInvocation<T>, ...args: any[]) => T): this;
}
export interface VoidSyncMethodStubSetter<T> {
thenReturn(head: T, ...tail: T[]): this;
thenReturn(): this;
thenReturnOnce(value: T): this;
thenThrow(head: Error, ...tail: Error[]): this;
thenThrowOnce(value: Error): this;
thenCall(func: (this: MockInvocation<T>, ...args: any[]) => T): this;
}
export interface AsyncMethodStubSetter<T, ResolveType> extends SyncMethodStubSetter<T> {
thenResolve(head: ResolveType, ...tail: ResolveType[]): this;
thenResolveOnce(value: ResolveType): this;
thenReject(head: any, ...tail: any[]): this;
thenRejectOnce(error: any): this;
}
export interface VoidAsyncMethodStubSetter<T, ResolveType> extends VoidSyncMethodStubSetter<T> {
thenResolve(head: ResolveType, ...tail: ResolveType[]): this;
thenResolve(): this;
thenResolveOnce(value: ResolveType): this;
thenReject(head: any, ...tail: any[]): this;
thenRejectOnce(error: any): this;
}
export declare class MethodStubSetter<T, ResolveType> implements AsyncMethodStubSetter<T, ResolveType>, VoidAsyncMethodStubSetter<T, ResolveType> {
private methodToStub;
private static globalGroupIndex;
private groupIndex;
constructor(methodToStub: MethodToStub);
thenReturn(...rest: T[]): this;
thenReturnOnce(value: T): this;
thenThrow(...rest: Error[]): this;
thenThrowOnce(error: Error): this;
thenCall(func: (this: MockInvocation<T>, ...args: any[]) => T): this;
thenResolve(...rest: ResolveType[]): this;
thenResolveOnce(value: ResolveType): this;
thenReject(...rest: any[]): this;
thenRejectOnce(error: any): this;
}