mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-03 19:42:27 +08:00
add new sinon stub types (setters, getters, values) (#16848)
* add new sinon types * bump sinon version
This commit is contained in:
15
types/sinon/index.d.ts
vendored
15
types/sinon/index.d.ts
vendored
@@ -1,6 +1,10 @@
|
||||
// Type definitions for Sinon 2.2
|
||||
// Type definitions for Sinon 2.3
|
||||
// Project: http://sinonjs.org/
|
||||
// Definitions by: William Sears <https://github.com/mrbigdog2u>, Jonathan Little <https://github.com/rationull>, Lukas Spieß <https://github.com/lumaxis>, Nico Jansen <https://github.com/nicojs>
|
||||
// Definitions by: William Sears <https://github.com/mrbigdog2u>
|
||||
// Jonathan Little <https://github.com/rationull>
|
||||
// Lukas Spieß <https://github.com/lumaxis>
|
||||
// Nico Jansen <https://github.com/nicojs>
|
||||
// James Garbutt <https://github.com/43081j>
|
||||
// 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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user