mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
feat(sinon): Make stub factory method optionally generic (#31606)
This commit is contained in:
parent
d77cdfe11e
commit
b68f2ee2ac
5
types/sinon/ts3.1/index.d.ts
vendored
5
types/sinon/ts3.1/index.d.ts
vendored
@ -626,10 +626,13 @@ declare namespace Sinon {
|
||||
}
|
||||
|
||||
interface SinonStubStatic {
|
||||
// Disable rule so assignment to typed stub works (see examples in tests).
|
||||
/**
|
||||
* Creates an anonymous stub function
|
||||
*/
|
||||
(): SinonStub;
|
||||
// tslint:disable-next-line no-unnecessary-generics
|
||||
<TArgs extends any[]= any[], R = any>(): SinonStub<TArgs, R>;
|
||||
|
||||
/**
|
||||
* Stubs all the object’s methods.
|
||||
* Note that it’s usually better practice to stub individual methods, particularly on objects that you don’t understand or control all the methods for (e.g. library dependencies).
|
||||
|
||||
@ -483,6 +483,23 @@ function testStub() {
|
||||
stub.withArgs('a', 2).returns(true);
|
||||
}
|
||||
|
||||
function testTypedStub() {
|
||||
class Foo {
|
||||
bar(baz: number, qux: string): boolean {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
let stub: sinon.SinonStub<[number, string], boolean> = sinon.stub();
|
||||
let stub2 = sinon.stub<[number, string], boolean>();
|
||||
const foo = new Foo();
|
||||
stub = sinon.stub(foo, 'bar');
|
||||
stub2 = sinon.stub(foo, 'bar');
|
||||
const result: boolean = stub(42, 'qux');
|
||||
const fooStub: sinon.SinonStubbedInstance<Foo> = {
|
||||
bar: sinon.stub()
|
||||
};
|
||||
}
|
||||
|
||||
function testMock() {
|
||||
const obj = {};
|
||||
const mock = sinon.mock(obj);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user