UNPKG

1.61 kBJavaScriptView Raw
1"use strict";
2// Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
3// Node module: @loopback/testlab
4// This file is licensed under the MIT License.
5// License text available at https://opensource.org/licenses/MIT
6Object.defineProperty(exports, "__esModule", { value: true });
7exports.createStubInstance = exports.sinon = void 0;
8const tslib_1 = require("tslib");
9const sinon_1 = tslib_1.__importDefault(require("sinon"));
10exports.sinon = sinon_1.default;
11/**
12 * Creates a new object with the given functions as the prototype and stubs all
13 * implemented functions.
14 *
15 * Note: The given constructor function is not invoked. See also the stub API.
16 *
17 * This is a helper method replacing `sinon.createStubInstance` and working
18 * around the limitations of TypeScript and Sinon, where Sinon is not able to
19 * list private/protected members in the type definition of the stub instance
20 * and therefore the stub instance cannot be assigned to places expecting TType.
21 * See also
22 * - https://github.com/Microsoft/TypeScript/issues/13543
23 * - https://github.com/DefinitelyTyped/DefinitelyTyped/issues/14811
24 *
25 * @typeParam TType - Type being stubbed.
26 * @param constructor - Object or class to stub.
27 * @returns A stubbed version of the constructor, with an extra property `stubs`
28 * providing access to stub API for individual methods.
29 */
30function createStubInstance(constructor) {
31 const stub = sinon_1.default.createStubInstance(constructor);
32 return Object.assign(stub, { stubs: stub });
33}
34exports.createStubInstance = createStubInstance;
35//# sourceMappingURL=sinon.js.map
\No newline at end of file