Expanded Sinon's createStubInstance to allow a TType generic (#16730)

* Expanded Sinon's createStubInstance types

* Defaulted createStubInstance behavior to not use the better types

TType gets inferred to `{}` by default. Odd.

* Removed commented out typings

* Removed unnecessary imports from i18next-tests

* Added TS 2.2 notices

* Bumped TS versions to 2.3

* Consolidated optional types for StubbableType

* Update index.d.ts
This commit is contained in:
Josh Goldberg
2017-06-03 15:04:06 -07:00
committed by Andy
parent bd91bdc631
commit 2bd01e84f7
11 changed files with 46 additions and 6 deletions
-5
View File
@@ -1,8 +1,3 @@
/// <reference types="sinon" />
/// <reference types="mocha" />
/// <reference types="expect.js" />
/// <reference types="jquery" />
import i18n = require("i18next");
i18n.init({
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/tubalmartin/karma-chai-sinon
// Definitions by: Václav Ostrožlík <https://github.com/vasek17>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
// TypeScript Version: 2.2
/// <reference types="chai" />
import Sinon = require("sinon");
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/bendrucker/sinon-as-promised
// Definitions by: igrayson <https://github.com/igrayson>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import * as s from "sinon";
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/domenic/sinon-chai
// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid/>, Jed Mao <https://github.com/jedmao/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="chai" />
/// <reference types="sinon" />
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/vitalets/sinon-chrome
// Definitions by: Tim Perry <https://github.com/pimterry>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="chrome"/>
/// <reference types="sinon"/>
+1 -1
View File
@@ -2,7 +2,7 @@
// Project: https://github.com/danawoodman/sinon-express-mock#readme
// Definitions by: Jared Chapiewsky <https://github.com/jpchip>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// TypeScript Version: 2.3
import * as Sinon from "sinon";
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/underscopeio/sinon-mongoose
// Definitions by: stevehipwell <https://github.com/stevehipwell>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
import * as s from "sinon";
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/substantial/sinon-stub-promise
// Definitions by: Thiago Temple <https://github.com/vintem>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
/// <reference types="sinon"/>
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/sinonjs/sinon-test
// Definitions by: Francis Saul <https://github.com/mummybot>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import * as Sinon from 'sinon';
+37
View File
@@ -6,6 +6,7 @@
// Nico Jansen <https://github.com/nicojs>
// James Garbutt <https://github.com/43081j>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
// sinon uses DOM dependencies which are absent in browser-less environment like node.js
// to avoid compiler errors this monkey patch is used
@@ -506,10 +507,46 @@ declare namespace Sinon {
// Utility overridables
interface SinonStatic {
/**
* Creates a new object with the given functions as the prototype and stubs all implemented functions.
*
* @param constructor Object or class to stub.
* @returns A stubbed version of the constructor.
* @remarks The given constructor function is not invoked. See also the stub API.
*/
createStubInstance(constructor: any): any;
/**
* Creates a new object with the given functions as the prototype and stubs all implemented functions.
*
* @type TType Type being stubbed.
* @param constructor Object or class to stub.
* @returns A stubbed version of the constructor.
* @remarks The given constructor function is not invoked. See also the stub API.
*/
createStubInstance<TType>(constructor: StubbableType<TType>): SinonStubbedInstance<TType>;
format(obj: any): string;
restore(object: any): void;
}
/**
* Stubbed type of an object with members replaced by stubs.
*
* @type TType Type being stubbed.
*/
interface StubbableType<TType> {
new(...args: any[]): TType;
}
/**
* An instance of a stubbed object type with members replaced by stubs.
*
* @type TType Object type being stubbed.
*/
type SinonStubbedInstance<TType> = {
[P in keyof TType]: SinonStub;
};
}
declare const Sinon: Sinon.SinonStatic;
+1
View File
@@ -231,6 +231,7 @@ class TestCreateStubInstance {
}
sinon.createStubInstance(TestCreateStubInstance).someTestMethod('some argument');
sinon.createStubInstance<TestCreateStubInstance>(TestCreateStubInstance).someTestMethod('some argument');
function testGetCalls() {
let double = sinon.spy((a: number) => a * 2);