sinon: resolve version issues

This commit is contained in:
James Garbutt 2018-11-27 11:58:30 +00:00 committed by 43081j
parent 91e0fb8638
commit b4715b48d6
17 changed files with 2377 additions and 207 deletions

View File

@ -2,7 +2,7 @@
// Project: https://github.com/tubalmartin/karma-chai-sinon
// Definitions by: Václav Ostrožlík <https://github.com/vasek17>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
// TypeScript Version: 3.0
// TypeScript Version: 2.8
/// <reference types="chai" />
import Sinon = require('sinon');

View File

@ -2,7 +2,7 @@
// Project: https://github.com/pawelgalazka/mochaccino#readme
// Definitions by: Thomas-P <https://github.com/thomas-p>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
// TypeScript Version: 2.8
import * as Sinon from 'sinon';
export interface Expect {
not: Expect;

View File

@ -2,7 +2,7 @@
// Project: https://github.com/shouldjs/sinon
// Definitions by: AryloYeung <https://github.com/Arylo>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
// TypeScript Version: 2.8
import * as s from 'sinon';
import should = require('should');

View File

@ -2,7 +2,7 @@
// Project: https://github.com/bendrucker/sinon-as-promised
// Definitions by: igrayson <https://github.com/igrayson>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
// TypeScript Version: 2.8
import * as s from "sinon";

View File

@ -4,7 +4,7 @@
// Jed Mao <https://github.com/jedmao>
// Eyal Lapid <https://github.com/elpdpt>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
// TypeScript Version: 2.8
/// <reference types="chai" />
/// <reference types="sinon" />

View File

@ -2,7 +2,7 @@
// Project: https://github.com/domenic/sinon-chai
// Definitions by: Kazi Manzur Rashid <https://github.com/kazimanzurrashid>, Jed Mao <https://github.com/jedmao>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
// TypeScript Version: 2.8
/// <reference types="chai" />
/// <reference types="sinon" />

View File

@ -4,7 +4,7 @@
// CRIMX <https://github.com/crimx>
// kobanyan <https://github.com/kobanyan>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
// TypeScript Version: 2.8
/// <reference types="chrome"/>
/// <reference types="sinon"/>

View File

@ -3,7 +3,7 @@
// Definitions by: Jared Chapiewsky <https://github.com/jpchip>
// Tomek Łaziuk <https://github.com/tlaziuk>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
// TypeScript Version: 2.8
import {
SinonStub,

View File

@ -2,7 +2,7 @@
// Project: https://github.com/underscopeio/sinon-mongoose
// Definitions by: stevehipwell <https://github.com/stevehipwell>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
// TypeScript Version: 2.8
import * as s from "sinon";

View File

@ -3,7 +3,7 @@
// Definitions by: Thiago Temple <https://github.com/vintem>
// Tim Stackhouse <https://github.com/tstackhouse>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
// TypeScript Version: 2.8
/// <reference types="sinon"/>

View File

@ -2,7 +2,7 @@
// Project: https://github.com/sinonjs/sinon-test
// Definitions by: Francis Saul <https://github.com/mummybot>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
// TypeScript Version: 2.8
import * as Sinon from 'sinon';

293
types/sinon/index.d.ts vendored
View File

@ -9,21 +9,21 @@
// Greg Jednaszewski <https://github.com/gjednaszewski>
// John Wood <https://github.com/johnjesse>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
// TypeScript Version: 2.8
// sinon uses DOM dependencies which are absent in browser-less environment like node.js
// to avoid compiler errors this monkey patch is used
// see more details in https://github.com/DefinitelyTyped/DefinitelyTyped/issues/11351
interface Event {} // tslint:disable-line no-empty-interface
interface Document {} // tslint:disable-line no-empty-interface
interface Event { } // tslint:disable-line no-empty-interface
interface Document { } // tslint:disable-line no-empty-interface
declare namespace Sinon {
interface SinonSpyCallApi<TArgs extends any = any, TReturnValue = any> {
interface SinonSpyCallApi {
// Properties
/**
* Array of received arguments.
*/
args: TArgs[];
args: any[];
// Methods
/**
@ -38,11 +38,11 @@ declare namespace Sinon {
* so a call that received the provided arguments (in the same spots) and possibly others as well will return true.
* @param args
*/
calledWith(...args: Array<TArgs|SinonMatcher>): boolean;
calledWith(...args: any[]): boolean;
/**
* Returns true if spy was called at least once with the provided arguments and no others.
*/
calledWithExactly(...args: Array<TArgs|SinonMatcher>): boolean;
calledWithExactly(...args: any[]): boolean;
/**
* Returns true if spy/stub was called the new operator.
* Beware that this is inferred based on the value of the this object and the spy functions prototype,
@ -53,31 +53,31 @@ declare namespace Sinon {
* Returns true if spy was called at exactly once with the provided arguments.
* @param args
*/
calledOnceWith(...args: Array<TArgs|SinonMatcher>): boolean;
calledOnceWithExactly(...args: Array<TArgs|SinonMatcher>): boolean;
calledOnceWith(...args: any[]): boolean;
calledOnceWithExactly(...args: any[]): boolean;
/**
* Returns true if spy was called with matching arguments (and possibly others).
* This behaves the same as spy.calledWith(sinon.match(arg1), sinon.match(arg2), ...).
* @param args
*/
calledWithMatch(...args: TArgs[]): boolean;
calledWithMatch(...args: any[]): boolean;
/**
* Returns true if call did not receive provided arguments.
* @param args
*/
notCalledWith(...args: Array<TArgs|SinonMatcher>): boolean;
notCalledWith(...args: any[]): boolean;
/**
* Returns true if call did not receive matching arguments.
* This behaves the same as spyCall.notCalledWith(sinon.match(arg1), sinon.match(arg2), ...).
* @param args
*/
notCalledWithMatch(...args: TArgs[]): boolean;
notCalledWithMatch(...args: any[]): boolean;
/**
* Returns true if spy returned the provided value at least once.
* Uses deep comparison for objects and arrays. Use spy.returned(sinon.match.same(obj)) for strict comparison (see matchers).
* @param value
*/
returned(value: TReturnValue|SinonMatcher): boolean;
returned(value: any): boolean;
/**
* Returns true if spy threw an exception at least once.
*/
@ -118,8 +118,7 @@ declare namespace Sinon {
yieldToOn(property: string, obj: any, ...args: any[]): void;
}
interface SinonSpyCall<TArgs extends any = any, TReturnValue = any>
extends SinonSpyCallApi<TArgs, TReturnValue> {
interface SinonSpyCall extends SinonSpyCallApi {
/**
* The calls this value.
*/
@ -131,7 +130,7 @@ declare namespace Sinon {
/**
* Return value.
*/
returnValue: TReturnValue;
returnValue: any;
/**
* This property is a convenience for a calls callback.
* When the last argument in a call is a Function, then callback will reference that. Otherwise it will be undefined.
@ -154,11 +153,7 @@ declare namespace Sinon {
calledAfter(call: SinonSpyCall): boolean;
}
interface SinonSpy<TArgs extends any = any, TReturnValue = any>
extends Pick<
SinonSpyCallApi<TArgs, TReturnValue>,
Exclude<keyof SinonSpyCallApi<TArgs, TReturnValue>, 'args'>
> {
interface SinonSpy extends SinonSpyCallApi {
// Properties
/**
* The number of recorded calls.
@ -187,19 +182,19 @@ declare namespace Sinon {
/**
* The first call
*/
firstCall: SinonSpyCall<TArgs, TReturnValue>;
firstCall: SinonSpyCall;
/**
* The second call
*/
secondCall: SinonSpyCall<TArgs, TReturnValue>;
secondCall: SinonSpyCall;
/**
* The third call
*/
thirdCall: SinonSpyCall<TArgs, TReturnValue>;
thirdCall: SinonSpyCall;
/**
* The last call
*/
lastCall: SinonSpyCall<TArgs, TReturnValue>;
lastCall: SinonSpyCall;
/**
* Array of this objects, spy.thisValues[0] is the this object for the first call.
*/
@ -207,7 +202,7 @@ declare namespace Sinon {
/**
* Array of arguments received, spy.args[0] is an array of arguments received in the first call.
*/
args: TArgs[][];
args: any[][];
/**
* Array of exception objects thrown, spy.exceptions[0] is the exception thrown by the first call.
* If the call did not throw an error, the value at the calls location in .exceptions will be undefined.
@ -217,7 +212,7 @@ declare namespace Sinon {
* Array of return values, spy.returnValues[0] is the return value of the first call.
* If the call did not explicitly return a value, the value at the calls location in .returnValues will be undefined.
*/
returnValues: TReturnValue[];
returnValues: any[];
// Methods
(...args: any[]): any;
@ -246,7 +241,7 @@ declare namespace Sinon {
* This is useful to be more expressive in your assertions, where you can access the spy with the same call.
* @param args Expected args
*/
withArgs(...args: Array<TArgs|SinonMatcher>): SinonSpy<TArgs, TReturnValue>;
withArgs(...args: any[]): SinonSpy;
/**
* Returns true if the spy was always called with @param obj as this.
* @param obj
@ -255,29 +250,29 @@ declare namespace Sinon {
/**
* Returns true if spy was always called with the provided arguments (and possibly others).
*/
alwaysCalledWith(...args: Array<TArgs|SinonMatcher>): boolean;
alwaysCalledWith(...args: any[]): boolean;
/**
* Returns true if spy was always called with the exact provided arguments.
* @param args
*/
alwaysCalledWithExactly(...args: Array<TArgs|SinonMatcher>): boolean;
alwaysCalledWithExactly(...args: any[]): boolean;
/**
* Returns true if spy was always called with matching arguments (and possibly others).
* This behaves the same as spy.alwaysCalledWith(sinon.match(arg1), sinon.match(arg2), ...).
* @param args
*/
alwaysCalledWithMatch(...args: TArgs[]): boolean;
alwaysCalledWithMatch(...args: any[]): boolean;
/**
* Returns true if the spy/stub was never called with the provided arguments.
* @param args
*/
neverCalledWith(...args: Array<TArgs|SinonMatcher>): boolean;
neverCalledWith(...args: any[]): boolean;
/**
* Returns true if the spy/stub was never called with matching arguments.
* This behaves the same as spy.neverCalledWith(sinon.match(arg1), sinon.match(arg2), ...).
* @param args
*/
neverCalledWithMatch(...args: TArgs[]): boolean;
neverCalledWithMatch(...args: any[]): boolean;
/**
* Returns true if spy always threw an exception.
*/
@ -300,22 +295,22 @@ declare namespace Sinon {
* If the stub was never called with a function argument, yield throws an error.
* Returns an Array with all callbacks return values in the order they were called, if no error is thrown.
*/
invokeCallback(...args: TArgs[]): void;
invokeCallback(...args: any[]): void;
/**
* Set the displayName of the spy or stub.
* @param name
*/
named(name: string): SinonSpy<TArgs, TReturnValue>;
named(name: string): SinonSpy;
/**
* Returns the nth call.
* Accessing individual calls helps with more detailed behavior verification when the spy is called more than once.
* @param n
*/
getCall(n: number): SinonSpyCall<TArgs, TReturnValue>;
getCall(n: number): SinonSpyCall;
/**
* Returns an Array of all calls recorded by the spy.
*/
getCalls(): Array<SinonSpyCall<TArgs, TReturnValue>>;
getCalls(): SinonSpyCall[];
/**
* Resets the state of a spy.
*/
@ -355,15 +350,10 @@ declare namespace Sinon {
* The original method can be restored by calling object.method.restore().
* The returned spy is the function object which replaced the original method. spy === object.method.
*/
<T, K extends keyof T>(obj: T, method: K): T[K] extends (
...args: Array<infer TArgs>
) => infer TReturnValue
? SinonSpy<TArgs, TReturnValue>
: SinonSpy;
<T>(obj: T, method: keyof T): SinonSpy;
}
interface SinonStub<TArgs extends any = any, TReturnValue = any>
extends SinonSpy<TArgs, TReturnValue> {
interface SinonStub extends SinonSpy {
/**
* Resets the stubs behaviour to the default behaviour
* You can reset behaviour of all stubs using sinon.resetBehavior()
@ -381,13 +371,13 @@ declare namespace Sinon {
* Causes the stub to return promises using a specific Promise library instead of the global one when using stub.rejects or stub.resolves.
* Returns the stub to allow chaining.
*/
usingPromise(promiseLibrary: any): SinonStub<TArgs, TReturnValue>;
usingPromise(promiseLibrary: any): SinonStub;
/**
* Makes the stub return the provided @param obj value.
* @param obj
*/
returns(obj: TReturnValue): SinonStub<TArgs, TReturnValue>;
returns(obj: any): SinonStub;
/**
* Causes the stub to return the argument at the provided @param index.
* stub.returnsArg(0); causes the stub to return the first argument.
@ -395,12 +385,12 @@ declare namespace Sinon {
* starting from sinon@6.1.2, a TypeError will be thrown.
* @param index
*/
returnsArg(index: number): SinonStub<TArgs, TReturnValue>;
returnsArg(index: number): SinonStub;
/**
* Causes the stub to return its this value.
* Useful for stubbing jQuery-style fluent APIs.
*/
returnsThis(): SinonStub<TArgs, TReturnValue>;
returnsThis(): SinonStub;
/**
* Causes the stub to return a Promise which resolves to the provided value.
* When constructing the Promise, sinon uses the Promise.resolve method.
@ -408,26 +398,26 @@ declare namespace Sinon {
* The Promise library can be overwritten using the usingPromise method.
* Since sinon@2.0.0
*/
resolves(value?: any): SinonStub<TArgs, TReturnValue>;
resolves(value?: any): SinonStub;
/**
* Causes the stub to return a Promise which resolves to the argument at the provided index.
* stub.resolvesArg(0); causes the stub to return a Promise which resolves to the first argument.
* If the argument at the provided index is not available, a TypeError will be thrown.
*/
resolvesArg(index: number): SinonStub<TArgs, TReturnValue>;
resolvesArg(index: number): SinonStub;
/**
* Causes the stub to return a Promise which resolves to its this value.
*/
resolvesThis(): SinonStub<TArgs, TReturnValue>;
resolvesThis(): SinonStub;
/**
* Causes the stub to throw an exception (Error).
* @param type
*/
throws(type?: string): SinonStub<TArgs, TReturnValue>;
throws(type?: string): SinonStub;
/**
* Causes the stub to throw the provided exception object.
*/
throws(obj: any): SinonStub<TArgs, TReturnValue>;
throws(obj: any): SinonStub;
/**
* Causes the stub to throw the argument at the provided index.
* stub.throwsArg(0); causes the stub to throw the first argument as the exception.
@ -435,9 +425,9 @@ declare namespace Sinon {
* Since sinon@2.3.0
* @param index
*/
throwsArg(index: number): SinonStub<TArgs, TReturnValue>;
throwsException(type?: string): SinonStub<TArgs, TReturnValue>;
throwsException(obj: any): SinonStub<TArgs, TReturnValue>;
throwsArg(index: number): SinonStub;
throwsException(type?: string): SinonStub;
throwsException(obj: any): SinonStub;
/**
* Causes the stub to return a Promise which rejects with an exception (Error).
* When constructing the Promise, sinon uses the Promise.reject method.
@ -445,57 +435,53 @@ declare namespace Sinon {
* The Promise library can be overwritten using the usingPromise method.
* Since sinon@2.0.0
*/
rejects(): SinonStub<TArgs, TReturnValue>;
rejects(): SinonStub;
/**
* Causes the stub to return a Promise which rejects with an exception of the provided type.
* Since sinon@2.0.0
*/
rejects(errorType: string): SinonStub<TArgs, TReturnValue>;
rejects(errorType: string): SinonStub;
/**
* Causes the stub to return a Promise which rejects with the provided exception object.
* Since sinon@2.0.0
*/
rejects(value: any): SinonStub<TArgs, TReturnValue>;
rejects(value: any): SinonStub;
/**
* Causes the stub to call the argument at the provided index as a callback function.
* stub.callsArg(0); causes the stub to call the first argument as a callback.
* If the argument at the provided index is not available or is not a function, a TypeError will be thrown.
*/
callsArg(index: number): SinonStub<TArgs, TReturnValue>;
callsArg(index: number): SinonStub;
/**
* Causes the original method wrapped into the stub to be called when none of the conditional stubs are matched.
*/
callThrough(): SinonStub<TArgs, TReturnValue>;
callThrough(): SinonStub;
/**
* Like stub.callsArg(index); but with an additional parameter to pass the this context.
* @param index
* @param context
*/
callsArgOn(index: number, context: any): SinonStub<TArgs, TReturnValue>;
callsArgOn(index: number, context: any): SinonStub;
/**
* Like callsArg, but with arguments to pass to the callback.
* @param index
* @param args
*/
callsArgWith(index: number, ...args: any[]): SinonStub<TArgs, TReturnValue>;
callsArgWith(index: number, ...args: any[]): SinonStub;
/**
* Like above but with an additional parameter to pass the this context.
* @param index
* @param context
* @param args
*/
callsArgOnWith(
index: number,
context: any,
...args: any[]
): SinonStub<TArgs, TReturnValue>;
callsArgOnWith(index: number, context: any, ...args: any[]): SinonStub;
/**
* Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
* In Node environment the callback is deferred with process.nextTick.
* In a browser the callback is deferred with setTimeout(callback, 0).
* @param index
*/
callsArgAsync(index: number): SinonStub<TArgs, TReturnValue>;
callsArgAsync(index: number): SinonStub;
/**
* Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
* In Node environment the callback is deferred with process.nextTick.
@ -503,99 +489,91 @@ declare namespace Sinon {
* @param index
* @param context
*/
callsArgOnAsync(index: number, context: any): SinonStub<TArgs, TReturnValue>;
callsArgOnAsync(index: number, context: any): SinonStub;
/**
* Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
* In Node environment the callback is deferred with process.nextTick.
* In a browser the callback is deferred with setTimeout(callback, 0).
*/
callsArgWithAsync(index: number, ...args: any[]): SinonStub<TArgs, TReturnValue>;
callsArgWithAsync(index: number, ...args: any[]): SinonStub;
/**
* Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
* In Node environment the callback is deferred with process.nextTick.
* In a browser the callback is deferred with setTimeout(callback, 0).
*/
callsArgOnWithAsync(
index: number,
context: any,
...args: any[]
): SinonStub<TArgs, TReturnValue>;
callsArgOnWithAsync(index: number, context: any, ...args: any[]): SinonStub;
/**
* Makes the stub call the provided @param func when invoked.
* @param func
*/
callsFake(func: (...args: TArgs[]) => TReturnValue): SinonStub<TArgs, TReturnValue>;
callsFake(func: (...args: any[]) => any): SinonStub;
/**
* Replaces a new getter for this stub.
*/
get(func: () => any): SinonStub<TArgs, TReturnValue>;
get(func: () => any): SinonStub;
/**
* Defines a new setter for this stub.
* @param func
*/
set(func: (v: any) => void): SinonStub<TArgs, TReturnValue>;
set(func: (v: any) => void): SinonStub;
/**
* Defines the behavior of the stub on the @param n call. Useful for testing sequential interactions.
* There are methods onFirstCall, onSecondCall,onThirdCall to make stub definitions read more naturally.
* onCall can be combined with all of the behavior defining methods in this section. In particular, it can be used together with withArgs.
* @param n
*/
onCall(n: number): SinonStub<TArgs, TReturnValue>;
onCall(n: number): SinonStub;
/**
* Alias for stub.onCall(0);
*/
onFirstCall(): SinonStub<TArgs, TReturnValue>;
onFirstCall(): SinonStub;
/**
* Alias for stub.onCall(1);
*/
onSecondCall(): SinonStub<TArgs, TReturnValue>;
onSecondCall(): SinonStub;
/**
* Alias for stub.onCall(2);
*/
onThirdCall(): SinonStub<TArgs, TReturnValue>;
onThirdCall(): SinonStub;
/**
* Defines a new value for this stub.
* @param val
*/
value(val: any): SinonStub<TArgs, TReturnValue>;
value(val: any): SinonStub;
/**
* Set the displayName of the spy or stub.
* @param name
*/
named(name: string): SinonStub<TArgs, TReturnValue>;
named(name: string): SinonStub;
/**
* Similar to callsArg.
* Causes the stub to call the first callback it receives with the provided arguments (if any).
* If a method accepts more than one callback, you need to use callsArg to have the stub invoke other callbacks than the first one.
*/
yields(...args: any[]): SinonStub<TArgs, TReturnValue>;
yields(...args: any[]): SinonStub;
/**
* Like above but with an additional parameter to pass the this context.
*/
yieldsOn(context: any, ...args: any[]): SinonStub<TArgs, TReturnValue>;
yieldsRight(...args: any[]): SinonStub<TArgs, TReturnValue>;
yieldsOn(context: any, ...args: any[]): SinonStub;
yieldsRight(...args: any[]): SinonStub;
/**
* Causes the spy to invoke a callback passed as a property of an object to the spy.
* Like yields, yieldsTo grabs the first matching argument, finds the callback and calls it with the (optional) arguments.
* @param property
* @param args
*/
yieldsTo(property: string, ...args: any[]): SinonStub<TArgs, TReturnValue>;
yieldsTo(property: string, ...args: any[]): SinonStub;
/**
* Like above but with an additional parameter to pass the this context.
*/
yieldsToOn(
property: string,
context: any,
...args: any[]
): SinonStub<TArgs, TReturnValue>;
yieldsToOn(property: string, context: any, ...args: any[]): SinonStub;
/**
* Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
* In Node environment the callback is deferred with process.nextTick.
* In a browser the callback is deferred with setTimeout(callback, 0).
* @param args
*/
yieldsAsync(...args: any[]): SinonStub<TArgs, TReturnValue>;
yieldsAsync(...args: any[]): SinonStub;
/**
* Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
* In Node environment the callback is deferred with process.nextTick.
@ -603,7 +581,7 @@ declare namespace Sinon {
* @param context
* @param args
*/
yieldsOnAsync(context: any, ...args: any[]): SinonStub<TArgs, TReturnValue>;
yieldsOnAsync(context: any, ...args: any[]): SinonStub;
/**
* Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
* In Node environment the callback is deferred with process.nextTick.
@ -611,7 +589,7 @@ declare namespace Sinon {
* @param property
* @param args
*/
yieldsToAsync(property: string, ...args: any[]): SinonStub<TArgs, TReturnValue>;
yieldsToAsync(property: string, ...args: any[]): SinonStub;
/**
* Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
* In Node environment the callback is deferred with process.nextTick.
@ -620,18 +598,14 @@ declare namespace Sinon {
* @param context
* @param args
*/
yieldsToOnAsync(
property: string,
context: any,
...args: any[]
): SinonStub<TArgs, TReturnValue>;
yieldsToOnAsync(property: string, context: any, ...args: any[]): SinonStub;
/**
* Stubs the method only for the provided arguments.
* This is useful to be more expressive in your assertions, where you can access the spy with the same call.
* It is also useful to create a stub that can act differently in response to different arguments.
* @param args
*/
withArgs(...args: Array<TArgs|SinonMatcher>): SinonStub<TArgs, TReturnValue>;
withArgs(...args: any[]): SinonStub;
}
interface SinonStubStatic {
@ -651,11 +625,7 @@ declare namespace Sinon {
* An exception is thrown if the property is not already a function.
* The original function can be restored by calling object.method.restore(); (or stub.restore();).
*/
<T, K extends keyof T>(obj: T, method: K): T[K] extends (
...args: Array<infer TArgs>
) => infer TReturnValue
? SinonStub<TArgs, TReturnValue>
: SinonStub;
<T>(obj: T, method: keyof T): SinonStub;
}
interface SinonExpectation extends SinonStub {
@ -757,22 +727,11 @@ declare namespace Sinon {
interface SinonFakeTimers {
now: number;
setTimeout(
callback: (...args: any[]) => void,
timeout: number,
...args: any[]
): SinonTimerId;
setTimeout(callback: (...args: any[]) => void, timeout: number, ...args: any[]): SinonTimerId;
clearTimeout(id: SinonTimerId): void;
setInterval(
callback: (...args: any[]) => void,
timeout: number,
...args: any[]
): SinonTimerId;
setInterval(callback: (...args: any[]) => void, timeout: number, ...args: any[]): SinonTimerId;
clearInterval(id: SinonTimerId): void;
setImmediate(
callback: (...args: any[]) => void,
...args: any[]
): SinonTimerId;
setImmediate(callback: (...args: any[]) => void, ...args: any[]): SinonTimerId;
clearImmediate(id: SinonTimerId): void;
requestAnimationFrame(callback: (...args: any[]) => void): number;
cancelAnimationFrame(id: number): void;
@ -806,30 +765,9 @@ declare namespace Sinon {
Date(year: number, month: number): Date;
Date(year: number, month: number, day: number): Date;
Date(year: number, month: number, day: number, hour: number): Date;
Date(
year: number,
month: number,
day: number,
hour: number,
minute: number
): Date;
Date(
year: number,
month: number,
day: number,
hour: number,
minute: number,
second: number
): Date;
Date(
year: number,
month: number,
day: number,
hour: number,
minute: number,
second: number,
ms: number
): Date;
Date(year: number, month: number, day: number, hour: number, minute: number): Date;
Date(year: number, month: number, day: number, hour: number, minute: number, second: number): Date;
Date(year: number, month: number, day: number, hour: number, minute: number, second: number, ms: number): Date;
/**
* Restore the faked methods.
@ -950,7 +888,7 @@ declare namespace Sinon {
}
interface SinonFakeXMLHttpRequestStatic {
new (): SinonFakeXMLHttpRequest;
new(): SinonFakeXMLHttpRequest;
/**
* Default false.
* When set to true, Sinon will check added filters if certain requests should be unfaked
@ -962,15 +900,7 @@ declare namespace Sinon {
* If the filter returns true, the request will not be faked.
* @param filter
*/
addFilter(
filter: (
method: string,
url: string,
async: boolean,
username: string,
password: string
) => boolean
): void;
addFilter(filter: (method: string, url: string, async: boolean, username: string, password: string) => boolean): void;
/**
* By assigning a function to the onCreate property of the returned object from useFakeXMLHttpRequest()
* you can subscribe to newly created FakeXMLHttpRequest objects. See below for the fake xhr object API.
@ -1036,10 +966,7 @@ declare namespace Sinon {
/**
* Responds to all requests to given URL, e.g. /posts/1.
*/
respondWith(
url: string,
fn: (xhr: SinonFakeXMLHttpRequest) => void
): void;
respondWith(url: string, fn: (xhr: SinonFakeXMLHttpRequest) => void): void;
/**
* Responds to all method requests to the given URL with the given response.
* method is an HTTP verb.
@ -1054,11 +981,7 @@ declare namespace Sinon {
* Responds to all method requests to the given URL with the given response.
* method is an HTTP verb.
*/
respondWith(
method: string,
url: string,
fn: (xhr: SinonFakeXMLHttpRequest) => void
): void;
respondWith(method: string, url: string, fn: (xhr: SinonFakeXMLHttpRequest) => void): void;
/**
* URL may be a regular expression, e.g. /\\/post\\//\\d+
* If the response is a Function, it will be passed any capture groups from the regular expression along with the XMLHttpRequest object:
@ -1073,10 +996,7 @@ declare namespace Sinon {
* URL may be a regular expression, e.g. /\\/post\\//\\d+
* If the response is a Function, it will be passed any capture groups from the regular expression along with the XMLHttpRequest object:
*/
respondWith(
url: RegExp,
fn: (xhr: SinonFakeXMLHttpRequest) => void
): void;
respondWith(url: RegExp, fn: (xhr: SinonFakeXMLHttpRequest) => void): void;
/**
* Responds to all method requests to URLs matching the regular expression.
*/
@ -1088,11 +1008,7 @@ declare namespace Sinon {
/**
* Responds to all method requests to URLs matching the regular expression.
*/
respondWith(
method: string,
url: RegExp,
fn: (xhr: SinonFakeXMLHttpRequest) => void
): void;
respondWith(method: string, url: RegExp, fn: (xhr: SinonFakeXMLHttpRequest) => void): void;
/**
* Causes all queued asynchronous requests to receive a response.
* If none of the responses added through respondWith match, the default response is [404, {}, ""].
@ -1221,10 +1137,7 @@ declare namespace Sinon {
* @param spyOrSpyCall
* @param args
*/
calledWithExactly(
spyOrSpyCall: SinonSpy | SinonSpyCall,
...args: any[]
): void;
calledWithExactly(spyOrSpyCall: SinonSpy | SinonSpyCall, ...args: any[]): void;
/**
* Passes if spy was always called with the provided arguments and no others.
*/
@ -1234,10 +1147,7 @@ declare namespace Sinon {
* This behaves the same way as sinon.assert.calledWith(spy, sinon.match(arg1), sinon.match(arg2), ...).
* Its possible to assert on a dedicated spy call: sinon.assert.calledWithMatch(spy.secondCall, arg1, arg2, ...);.
*/
calledWithMatch(
spyOrSpyCall: SinonSpy | SinonSpyCall,
...args: any[]
): void;
calledWithMatch(spyOrSpyCall: SinonSpy | SinonSpyCall, ...args: any[]): void;
/**
* Passes if spy was always called with matching arguments.
* This behaves the same way as sinon.assert.alwaysCalledWith(spy, sinon.match(arg1), sinon.match(arg2), ...).
@ -1529,7 +1439,7 @@ declare namespace Sinon {
* @template TType Object type being stubbed.
*/
type SinonStubbedInstance<TType> = {
[P in keyof TType]: SinonStubbedMember<TType[P]>
[P in keyof TType]: SinonStubbedMember<TType[P]>;
};
/**
@ -1619,9 +1529,7 @@ declare namespace Sinon {
* You would have to call either clock.next(), clock.tick(), clock.runAll() or clock.runToLast() (see example below). Please refer to the lolex documentation for more information.
* @param config
*/
useFakeTimers(
config?: number | Date | Partial<SinonFakeTimersConfig>
): SinonFakeTimers;
useFakeTimers(config?: number | Date | Partial<SinonFakeTimersConfig>): SinonFakeTimers;
/**
* Causes Sinon to replace the native XMLHttpRequest object in browsers that support it with a custom implementation which does not send actual requests.
* In browsers that support ActiveXObject, this constructor is replaced, and fake objects are returned for XMLHTTP progIds.
@ -1675,8 +1583,7 @@ declare namespace Sinon {
replace<T, TKey extends keyof T>(
obj: T,
prop: TKey,
replacement: T[TKey]
): T[TKey];
replacement: T[TKey]): T[TKey];
/**
* Replaces getter for property on object with replacement argument. Attempts to replace an already replaced getter cause an exception.
* replacement must be a Function, and can be instances of spies, stubs and fakes.
@ -1687,8 +1594,7 @@ declare namespace Sinon {
replaceGetter<T, TKey extends keyof T>(
obj: T,
prop: TKey,
replacement: () => T[TKey]
): () => T[TKey];
replacement: () => T[TKey]): () => T[TKey];
/**
* Replaces setter for property on object with replacement argument. Attempts to replace an already replaced setter cause an exception.
* replacement must be a Function, and can be instances of spies, stubs and fakes.
@ -1699,8 +1605,7 @@ declare namespace Sinon {
replaceSetter<T, TKey extends keyof T>(
obj: T,
prop: TKey,
replacement: (val: T[TKey]) => void
): (val: T[TKey]) => void;
replacement: (val: T[TKey]) => void): (val: T[TKey]) => void;
/**
* Creates a new object with the given functions as the prototype and stubs all implemented functions.
@ -1710,9 +1615,7 @@ declare namespace Sinon {
* @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>): SinonStubbedInstance<TType>;
}
interface SinonApi {

7
types/sinon/package.json Normal file
View File

@ -0,0 +1,7 @@
{
"private": true,
"types": "index",
"typesVersions": {
">=3.1.0-0": { "*": ["ts3.1/*"] }
}
}

View File

@ -293,7 +293,7 @@ function testTypedSpy() {
foo(a: number, b: string): number {
return 3;
}
}
};
const instance = new cls();
const spy = sinon.spy(instance, 'foo');

1747
types/sinon/ts3.1/index.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,488 @@
import sinon = require("sinon");
function testSandbox() {
const obj = {};
sinon.createSandbox({
injectInto: obj,
properties: ['spy', 'stub'],
useFakeTimers: true,
useFakeServer: true
});
sinon.createSandbox({
injectInto: null
});
sinon.createSandbox({
useFakeTimers: {
now: 1000,
shouldAdvanceTime: false
},
useFakeServer: sinon.fakeServer.create()
});
sinon.createSandbox(sinon.defaultConfig);
sinon.sandbox.create();
sinon.sandbox.create(sinon.defaultConfig);
const sb = sinon.createSandbox();
sb.assert.pass('foo');
sb.clock.tick(1000);
sb.spy();
sb.stub();
sb.mock(obj);
sb.useFakeTimers();
sb.useFakeTimers(1000);
sb.useFakeTimers(new Date());
sb.useFakeTimers({
now: 1000
});
const xhr = sb.useFakeXMLHttpRequest();
xhr.useFilters = true;
xhr.restore();
const server = sb.useFakeServer();
server.respondWith('foo');
sb.restore();
sb.reset();
sb.resetHistory();
sb.resetBehavior();
sb.usingPromise(Promise);
sb.verify();
sb.verifyAndRestore();
const replaceMe = {
prop: 5,
method() { return 6; },
get getter() { return 7; },
get setter() { return true; },
set setter(val) { }
};
sb.replace(replaceMe, 'prop', 10);
sb.replace(replaceMe, 'method', sb.spy());
sb.replaceGetter(replaceMe, 'getter', () => 14);
sb.replaceSetter(replaceMe, 'setter', (v) => { });
const cls = class {
foo() { }
bar: number;
};
const PrivateFoo = class {
private constructor() { }
foo() { }
bar: number;
static create() {
return new PrivateFoo();
}
};
const stubInstance = sb.createStubInstance(cls);
const privateFooStubbedInstance = sb.createStubInstance(PrivateFoo);
stubInstance.foo.calledWith('foo');
privateFooStubbedInstance.foo.calledWith('foo');
const clsFoo: sinon.SinonStub = stubInstance.foo;
const privateFooFoo: sinon.SinonStub = privateFooStubbedInstance.foo;
const clsBar: number = stubInstance.bar;
const privateFooBar: number = privateFooStubbedInstance.bar;
}
function testFakeServer() {
let s = sinon.fakeServer.create();
s = sinon.fakeServerWithClock.create();
sinon.fakeServer.create({
autoRespond: true,
autoRespondAfter: 3,
fakeHTTPMethods: true,
respondImmediately: false
});
sinon.fakeServer.create({
autoRespond: true,
autoRespondAfter: 3
});
}
function testXHR() {
const xhr = new sinon.FakeXMLHttpRequest();
const headers = xhr.getAllResponseHeaders();
const header = xhr.getResponseHeader('foo');
xhr.setResponseHeaders({ 'Content-Type': 'text/html' });
xhr.setResponseBody('foo');
xhr.respond(200, { 'Content-Type': 'foo' }, 'bar');
xhr.error();
sinon.FakeXMLHttpRequest.useFilters = true;
sinon.FakeXMLHttpRequest.addFilter((method, url, async, user, pass) => true);
sinon.FakeXMLHttpRequest.onCreate = (xhr) => { };
sinon.FakeXMLHttpRequest.restore();
}
function testClock() {
let clock = sinon.clock.create(1000);
clock = sinon.clock.create(new Date());
let now = 0;
now = clock.now;
const fn = () => { };
clock.setTimeout(fn, 0);
clock.setTimeout(fn, 0, 'a', 'b');
clock.setInterval(fn, 0);
clock.setInterval(fn, 0, 'a', 'b');
clock.setImmediate(fn);
clock.setImmediate(fn, 'a', 'b');
clock.requestAnimationFrame(fn);
let timer = clock.setTimeout(fn, 0);
clock.clearTimeout(timer);
timer = clock.setInterval(fn, 0);
clock.clearInterval(timer);
timer = clock.setImmediate(fn);
clock.clearImmediate(timer);
const animTimer = clock.requestAnimationFrame(fn);
clock.cancelAnimationFrame(animTimer);
clock.nextTick(fn);
clock.tick(1);
clock.tick('00:10');
clock.next();
clock.runAll();
clock.runToLast();
clock.reset();
clock.runMicrotasks();
clock.runToFrame();
clock.restore();
clock.uninstall();
clock.setSystemTime(1000);
clock.setSystemTime(new Date());
}
function testExpectation() {
const obj = {};
let ex = sinon.expectation.create();
ex = sinon.expectation.create('some name');
ex.atLeast(5).atMost(10);
ex.never();
ex.once();
ex.twice();
ex.thrice();
ex.exactly(5);
ex.withArgs('a', 'b');
ex.withExactArgs('a', 'b');
ex.on(obj);
ex.verify();
ex.restore();
}
function testMatch() {
const obj = {};
const fn = () => { };
sinon.match(5).test(5);
sinon.match('str').test('foo');
sinon.match(/foo/).test('foo');
sinon.match({ a: 5, b: 6 }).test({});
sinon.match((v) => true).test('foo');
sinon.match((v) => true, 'some message').test('foo');
sinon.match.any.test('foo');
sinon.match.defined.test('foo');
sinon.match.truthy.test('foo');
sinon.match.falsy.test('foo');
sinon.match.bool.test('foo');
sinon.match.number.test('foo');
sinon.match.string.test('foo');
sinon.match.object.test('foo');
sinon.match.func.test(fn);
sinon.match.map.test(new Map([['a', 1], ['b', 2]]));
sinon.match.set.test(new Set([1, 2, 3]));
sinon.match.array.test([1, 2, 3]);
sinon.match.regexp.test('foo');
sinon.match.date.test('foo');
sinon.match.symbol.test('foo');
sinon.match.same(obj);
sinon.match.typeOf('string').test('foo');
sinon.match.instanceOf(fn).test('foo');
sinon.match.has('prop').test(obj);
sinon.match.has('prop', 123).test(obj);
sinon.match.hasOwn('prop').test(obj);
sinon.match.hasOwn('prop', 123).test(obj);
sinon.match.hasNested('prop.foo.bar').test(obj);
sinon.match.hasNested('prop.foo.bar', 123).test(obj);
sinon.match.every(sinon.match.number).test([1, 2, 'three']);
sinon.match.some(sinon.match.number).test([1, 2, 'three']);
sinon.match.array.deepEquals([{ a: 'b' }]).test([]);
sinon.match.array.startsWith([{ a: 'b' }]).test([]);
sinon.match.array.deepEquals([{ a: 'b' }]).test([]);
sinon.match.array.contains([{ a: 'b' }]).test([]);
sinon.match.map.deepEquals(new Map([['a', true], ['b', false]])).test(new Map());
sinon.match.map.contains(new Map([['a', true]])).test(new Map());
}
function testFake() {
const fn = () => { };
let fake = sinon.fake();
fake = sinon.fake(() => true);
fake = sinon.fake.returns(5);
fake = sinon.fake.throws('foo');
fake = sinon.fake.throws(new Error('foo'));
fake = sinon.fake.resolves('foo');
fake = sinon.fake.rejects('foo');
fake = sinon.fake.yields(1, 2, fn);
fake = sinon.fake.yieldsAsync(1, 2, fn);
fake.calledWith('foo');
}
function testAssert() {
const spy = sinon.spy();
const spyTwo = sinon.spy();
const obj = {};
sinon.assert.fail();
sinon.assert.fail('foo');
sinon.assert.pass('foo');
sinon.assert.notCalled(spy);
sinon.assert.called(spy);
sinon.assert.calledOnce(spy);
sinon.assert.calledTwice(spy);
sinon.assert.calledThrice(spy);
sinon.assert.callCount(spy, 3);
sinon.assert.callOrder(spy, spyTwo);
sinon.assert.calledOn(spy, obj);
sinon.assert.calledOn(spy.firstCall, obj);
sinon.assert.alwaysCalledOn(spy, obj);
sinon.assert.alwaysCalledWith(spy, 'a', 'b', 'c');
sinon.assert.neverCalledWith(spy, 'a', 'b', 'c');
sinon.assert.calledWithExactly(spy, 'a', 'b', 'c');
sinon.assert.alwaysCalledWithExactly(spy, 'a', 'b', 'c');
sinon.assert.calledWithMatch(spy, 'a', 'b', 'c');
sinon.assert.calledWithMatch(spy.firstCall, 'a', 'b', 'c');
sinon.assert.alwaysCalledWithMatch(spy, 'a', 'b', 'c');
sinon.assert.neverCalledWithMatch(spy, 'a', 'b', 'c');
sinon.assert.calledWithNew(spy);
sinon.assert.calledWithNew(spy.firstCall);
sinon.assert.threw(spy);
sinon.assert.threw(spy.firstCall);
sinon.assert.threw(spy, 'foo error');
sinon.assert.threw(spy.firstCall, 'foo error');
sinon.assert.threw(spy, new Error('foo'));
sinon.assert.threw(spy.firstCall, new Error('foo'));
sinon.assert.alwaysThrew(spy);
sinon.assert.alwaysThrew(spy, 'foo error');
sinon.assert.alwaysThrew(spy, new Error('foo'));
sinon.assert.match('a', 'b');
sinon.assert.match(1, 1 + 1);
sinon.assert.match({ a: 1 }, { b: 2, c: 'abc' });
sinon.assert.expose(obj);
sinon.assert.expose(obj, { prefix: 'blah' });
sinon.assert.expose(obj, { includeFail: true });
}
function testTypedSpy() {
const cls = class {
foo(a: number, b: string): number {
return 3;
}
};
const instance = new cls();
const spy = sinon.spy(instance, 'foo');
spy.calledWith(5, 'x');
spy.calledWith(sinon.match(5), 'x');
spy.calledWithExactly(5, 'x');
spy.calledWithExactly(5, sinon.match('x'));
spy.calledOnceWith(5, 'x');
spy.calledOnceWith(sinon.match(5), 'x');
spy.notCalledWith(5, 'x');
spy.notCalledWith(sinon.match(5), 'x');
spy.returned(5);
spy.returned(sinon.match(5));
spy.withArgs(sinon.match(5), 'x').calledWith(5, 'x');
spy.alwaysCalledWith(sinon.match(5), 'x');
spy.alwaysCalledWith(5, 'x');
spy.alwaysCalledWithExactly(sinon.match(5), 'x');
spy.alwaysCalledWithExactly(5, 'x');
spy.neverCalledWith(sinon.match(5), 'x');
spy.neverCalledWith(5, 'x');
const stub = sinon.stub(instance, 'foo');
stub.withArgs(5, 'x').returns(3);
stub.withArgs(sinon.match(5), 'x').returns(5);
}
function testSpy() {
const fn = () => { };
const obj = class {
foo() { }
};
const instance = new obj();
let spy = sinon.spy();
const spyTwo = sinon.spy().named('spyTwo');
spy = sinon.spy(fn);
spy = sinon.spy(instance, 'foo');
let count = 0;
count = spy.callCount;
let called = false;
called = spy.called;
called = spy.notCalled;
called = spy.calledOnce;
called = spy.calledTwice;
called = spy.calledThrice;
let arr: any[] = [];
arr = spy.thisValues;
arr = spy.args;
arr = spy.exceptions;
arr = spy.returnValues;
spy('a', 'b');
spy(1, 2);
spy(true);
spy.calledBefore(spyTwo);
spy.calledAfter(spyTwo);
spy.calledImmediatelyBefore(spyTwo);
spy.calledImmediatelyAfter(spyTwo);
spy.calledWithNew();
spy.withArgs('a', 1).calledBefore(spyTwo);
spy.alwaysCalledOn(instance);
spy.alwaysCalledWith('a', 1);
spy.alwaysCalledWith('a');
spy.alwaysCalledWithExactly('a', 1);
spy.alwaysCalledWithMatch('foo');
spy.neverCalledWith('b', 2);
spy.neverCalledWith('b');
spy.neverCalledWithMatch('foo', 'bar');
spy.alwaysThrew();
spy.alwaysThrew('foo');
spy.alwaysThrew(new Error('foo'));
spy.alwaysReturned('foo');
spy.invokeCallback('a', 'b');
spy.calledOn(instance);
spy.calledWith('a', 2);
spy.calledWithExactly('a', 2);
spy.calledOnceWith('a', 2);
spy.calledOnceWithExactly('a', 2);
spy.calledWithMatch('bar', 2);
spy.notCalledWith('a', 2);
spy.notCalledWithMatch('a', 2);
spy.returned(true);
spy.returned('foo');
spy.returned(2);
spy.threw();
spy.threw('foo');
spy.threw(new Error('foo'));
spy.callArg(1);
spy.callArgOn(1, instance);
spy.callArgOn(1, instance, 'a', 2);
spy.callArgWith(1, 'a', 2);
spy.callArgOnWith(1, instance, 'a', 2);
spy.yield('a', 2);
spy.yieldOn(instance, 'a', 2);
spy.yieldTo('prop', 'a', 2);
spy.yieldToOn('prop', instance, 'a', 2);
let call = spy.firstCall;
call = spy.secondCall;
call = spy.thirdCall;
call = spy.lastCall;
call = spy.getCall(1);
call = spy.getCalls()[0];
call.calledBefore(call);
call.calledAfter(call);
call.calledWithNew();
spy.resetHistory();
spy.restore();
}
function testStub() {
const obj = class {
foo() { }
};
const instance = new obj();
let stub = sinon.stub();
stub = sinon.stub(instance, 'foo').named('namedStub');
const spy: sinon.SinonSpy = stub;
sinon.stub(instance);
stub.reset();
stub.resetBehavior();
stub.usingPromise(Promise);
stub.returns(true);
stub.returns(5);
stub.returns('foo');
stub.returnsArg(1);
stub.returnsThis();
stub.resolves();
stub.resolves('foo');
stub.resolvesArg(1);
stub.resolvesThis();
stub.throws();
stub.throws('err');
stub.throws(new Error('err'));
stub.throwsArg(1);
stub.throwsException('err');
stub.throwsException(new Error('err'));
stub.rejects();
stub.rejects('TypeError');
stub.rejects(1234);
stub.callsArg(1);
stub.callThrough();
stub.callsArgOn(1, instance);
stub.callsArgWith(1, 'a', 2);
stub.callsArgAsync(1);
stub.callsArgOnAsync(1, instance);
stub.callsArgWithAsync(1, 'a', 2);
stub.callsArgOnWithAsync(1, instance, 'a', 2);
stub.callsFake((s1, s2, s3) => { });
stub.callsFake(() => { });
stub.get(() => true);
stub.set((v) => { });
stub.onCall(1).returns(true);
stub.onFirstCall().resolves('foo');
stub.onSecondCall().resolves('foo');
stub.onThirdCall().resolves('foo');
stub.value('foo');
stub.yields('a', 2);
stub.yieldsOn(instance, 'a', 2);
stub.yieldsRight('a', 2);
stub.yieldsTo('foo', 'a', 2);
stub.yieldsToOn('foo', instance, 'a', 2);
stub.yieldsAsync('a', 2);
stub.yieldsOnAsync(instance, 'a', 2);
stub.yieldsToAsync('foo', 'a', 2);
stub.yieldsToOnAsync('foo', instance, 'a', 2);
stub.withArgs('a', 2).returns(true);
}
function testMock() {
const obj = {};
const mock = sinon.mock(obj);
mock.expects('method').atLeast(2).atMost(5);
mock.restore();
mock.verify();
}

View File

@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../../",
"typeRoots": [
"../../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"sinon-tests.ts"
]
}