UNPKG

1.2 kBTypeScriptView Raw
1import sinon, { SinonSpy } from 'sinon';
2export { sinon, SinonSpy };
3export declare type StubbedInstanceWithSinonAccessor<T> = T & {
4 stubs: sinon.SinonStubbedInstance<T>;
5};
6/**
7 * Creates a new object with the given functions as the prototype and stubs all
8 * implemented functions.
9 *
10 * Note: The given constructor function is not invoked. See also the stub API.
11 *
12 * This is a helper method replacing `sinon.createStubInstance` and working
13 * around the limitations of TypeScript and Sinon, where Sinon is not able to
14 * list private/protected members in the type definition of the stub instance
15 * and therefore the stub instance cannot be assigned to places expecting TType.
16 * See also
17 * - https://github.com/Microsoft/TypeScript/issues/13543
18 * - https://github.com/DefinitelyTyped/DefinitelyTyped/issues/14811
19 *
20 * @typeParam TType - Type being stubbed.
21 * @param constructor - Object or class to stub.
22 * @returns A stubbed version of the constructor, with an extra property `stubs`
23 * providing access to stub API for individual methods.
24 */
25export declare function createStubInstance<TType>(constructor: sinon.StubbableType<TType>): StubbedInstanceWithSinonAccessor<TType>;