UNPKG

ts-sinon

Version:

sinon library extension to stub whole object and interfaces

14 lines (13 loc) 916 B
import * as sinon from "sinon"; export declare type StubbedInstance<T> = sinon.SinonStubbedInstance<T> & T; export declare type AllowedKeys<T, Condition> = { [Key in keyof T]: T[Key] extends Condition ? Key : never; }[keyof T]; export declare type ObjectMethodsKeys<T> = AllowedKeys<T, (...args: any[]) => any>[]; export declare type ObjectMethodsMap<T> = { [Key in keyof T]?: T[Key] extends (...args: any[]) => any ? ReturnType<T[Key]> : never; }; export declare function stubObject<T extends object>(object: T, methods?: ObjectMethodsKeys<T> | ObjectMethodsMap<T>): StubbedInstance<T>; export declare function stubConstructor<T extends new (...args: any[]) => any>(constructor: T, ...constructorArgs: ConstructorParameters<T> | undefined[]): StubbedInstance<InstanceType<T>>; export declare function stubInterface<T extends object>(methods?: ObjectMethodsMap<T>): StubbedInstance<T>; export default sinon;