diff --git a/types/sinon/index.d.ts b/types/sinon/index.d.ts index b3caa38657..68692f6d52 100644 --- a/types/sinon/index.d.ts +++ b/types/sinon/index.d.ts @@ -1,6 +1,10 @@ -// Type definitions for Sinon 2.2 +// Type definitions for Sinon 2.3 // Project: http://sinonjs.org/ -// Definitions by: William Sears , Jonathan Little , Lukas Spieß , Nico Jansen +// Definitions by: William Sears +// Jonathan Little +// Lukas Spieß +// Nico Jansen +// James Garbutt // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // sinon uses DOM dependencies which are absent in browser-less environment like node.js @@ -110,6 +114,9 @@ declare namespace Sinon { resolves(value?: any): SinonStub; throws(type?: string): SinonStub; throws(obj: any): SinonStub; + throwsArg(index: number): SinonStub; + throwsException(type?: string): SinonStub; + throwsException(obj: any): SinonStub; rejects(): SinonStub; rejects(errorType: string): SinonStub; rejects(value: any): SinonStub; @@ -123,12 +130,16 @@ declare namespace Sinon { callsArgWithAsync(index: number, ...args: any[]): SinonStub; callsArgOnWithAsync(index: number, context: any, ...args: any[]): SinonStub; callsFake(func: (...args: any[]) => void): SinonStub; + get(func: () => any): SinonStub; + set(func: (v: any) => void): SinonStub; onCall(n: number): SinonStub; onFirstCall(): SinonStub; onSecondCall(): SinonStub; onThirdCall(): SinonStub; + value(val: any): SinonStub; yields(...args: any[]): SinonStub; yieldsOn(context: any, ...args: any[]): SinonStub; + yieldsRight(...args: any[]): SinonStub; yieldsTo(property: string, ...args: any[]): SinonStub; yieldsToOn(property: string, context: any, ...args: any[]): SinonStub; yieldsAsync(...args: any[]): SinonStub; diff --git a/types/sinon/sinon-tests.ts b/types/sinon/sinon-tests.ts index fd2af880f3..177eb0e0dd 100644 --- a/types/sinon/sinon-tests.ts +++ b/types/sinon/sinon-tests.ts @@ -159,6 +159,41 @@ function testSetMatcher() { stub.calledWithMatch(sinon.match.set.contains(new Set([true]))); } +function testGetterStub() { + const myObj: any = { + prop: 'foo' + }; + + const stub = sinon.stub(myObj, 'prop').get(() => 'bar'); + stub.restore(); +} + +function testSetterStub() { + const myObj: any = { + prop: 'foo', + prop2: 'bar' + }; + + const stub = sinon.stub(myObj, 'prop').set((val: string) => myObj.prop2 = val); + stub.restore(); +} + +function testValueStub() { + const myObj: any = { + prop: 'foo' + }; + + const stub = sinon.stub(myObj, 'prop').value('bar'); + stub.restore(); +} + +function testThrowsStub() { + sinon.stub().throws(new Error('foo')); + sinon.stub().throwsException(new Error('foo')); + sinon.stub().throws('foo'); + sinon.stub().throwsException('foo'); +} + function testSpy() { const otherSpy = sinon.spy(); sinon.spy().calledAfter(otherSpy); @@ -182,6 +217,10 @@ testSpy(); testSymbolMatch(); testResetHistory(); testUsingPromises(); +testGetterStub(); +testSetterStub(); +testValueStub(); +testThrowsStub(); let clock = sinon.useFakeTimers(); clock.setSystemTime(1000);