mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-02-05 16:32:46 +00:00
Merge pull request #31395 from CalthorpeAnalytics/sinon-stubbed-member-params
@types/sinon: stub out SinonStubbedMember, so createStubInstance types arguments and return values
This commit is contained in:
commit
b15c3a62c3
1
types/sinon/index.d.ts
vendored
1
types/sinon/index.d.ts
vendored
@ -8,6 +8,7 @@
|
||||
// Josh Goldberg <https://github.com/joshuakgoldberg>
|
||||
// Greg Jednaszewski <https://github.com/gjednaszewski>
|
||||
// John Wood <https://github.com/johnjesse>
|
||||
// Alec Flett <https://github.com/alecf>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
|
||||
4
types/sinon/ts3.1/index.d.ts
vendored
4
types/sinon/ts3.1/index.d.ts
vendored
@ -1526,7 +1526,9 @@ declare namespace Sinon {
|
||||
/**
|
||||
* Replaces a type with a Sinon stub if it's a function.
|
||||
*/
|
||||
type SinonStubbedMember<T> = T extends Function ? SinonStub : T;
|
||||
type SinonStubbedMember<T> = T extends (
|
||||
...args: infer TArgs
|
||||
) => infer TReturnValue ? SinonStub<TArgs, TReturnValue> : T;
|
||||
|
||||
interface SinonFake {
|
||||
/**
|
||||
|
||||
@ -67,7 +67,7 @@ function testSandbox() {
|
||||
sb.replaceSetter(replaceMe, 'setter', (v) => { });
|
||||
|
||||
const cls = class {
|
||||
foo() { }
|
||||
foo(arg1: string, arg2: number) { return 1; }
|
||||
bar: number;
|
||||
};
|
||||
const PrivateFoo = class {
|
||||
@ -81,8 +81,8 @@ function testSandbox() {
|
||||
|
||||
const stubInstance = sb.createStubInstance(cls);
|
||||
const privateFooStubbedInstance = sb.createStubInstance(PrivateFoo);
|
||||
stubInstance.foo.calledWith('foo');
|
||||
privateFooStubbedInstance.foo.calledWith('foo');
|
||||
stubInstance.foo.calledWith('foo', 1);
|
||||
privateFooStubbedInstance.foo.calledWith();
|
||||
const clsFoo: sinon.SinonStub = stubInstance.foo;
|
||||
const privateFooFoo: sinon.SinonStub = privateFooStubbedInstance.foo;
|
||||
const clsBar: number = stubInstance.bar;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user