Merge pull request #33223 from aleung/master

sinon: add overrides parameter to createStubInstance
This commit is contained in:
Jesse Trinity
2019-02-26 14:23:18 -08:00
committed by GitHub
4 changed files with 17 additions and 3 deletions
+5 -1
View File
@@ -1618,10 +1618,14 @@ declare namespace Sinon {
*
* @template TType Type being stubbed.
* @param constructor Object or class to stub.
* @param overrides An optional map overriding created stubs
* @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>;
createStubInstance<TType>(
constructor: StubbableType<TType>,
overrides?: { [K in keyof TType]?: any }
): SinonStubbedInstance<TType>;
}
interface SinonApi {
+3
View File
@@ -87,6 +87,9 @@ function testSandbox() {
const privateFooFoo: sinon.SinonStub = privateFooStubbedInstance.foo;
const clsBar: number = stubInstance.bar;
const privateFooBar: number = privateFooStubbedInstance.bar;
sb.createStubInstance(cls, {
bar: 1
});
}
function testFakeServer() {
+4 -1
View File
@@ -1707,11 +1707,14 @@ declare namespace Sinon {
*
* @template TType Type being stubbed.
* @param constructor Object or class to stub.
* @param overrides An optional map overriding created stubs
* @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>
constructor: StubbableType<TType>,
overrides?: { [K in keyof TType]?:
SinonStubbedMember<TType[K]> | TType[K] extends (...args: any[]) => infer R ? R : TType[K] }
): SinonStubbedInstance<TType>;
}
+5 -1
View File
@@ -67,7 +67,7 @@ function testSandbox() {
sb.replaceSetter(replaceMe, 'setter', (v) => { });
const cls = class {
foo(arg1: string, arg2: number) { return 1; }
foo(arg1: string, arg2: number): number { return 1; }
bar: number;
};
const PrivateFoo = class {
@@ -87,6 +87,10 @@ function testSandbox() {
const privateFooFoo: sinon.SinonStub = privateFooStubbedInstance.foo;
const clsBar: number = stubInstance.bar;
const privateFooBar: number = privateFooStubbedInstance.bar;
sb.createStubInstance(cls, {
foo: (arg1: string, arg2: number) => 2,
bar: 1
});
}
function testFakeServer() {