cypress 9.2.1 → 9.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,6 @@
1
- // Type definitions for Sinon 7.5
1
+ // Type definitions for Sinon 9.0
2
2
  // Project: https://sinonjs.org
3
3
  // Definitions by: William Sears <https://github.com/mrbigdog2u>
4
- // Jonathan Little <https://github.com/rationull>
5
4
  // Lukas Spieß <https://github.com/lumaxis>
6
5
  // Nico Jansen <https://github.com/nicojs>
7
6
  // James Garbutt <https://github.com/43081j>
@@ -12,21 +11,26 @@
12
11
  // Simon Schick <https://github.com/SimonSchick>
13
12
  // Roey Berman <https://github.com/bergundy>
14
13
  // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
15
- // TypeScript Version: 2.8
14
+
15
+ import * as FakeTimers from '@sinonjs/fake-timers';
16
16
 
17
17
  // sinon uses DOM dependencies which are absent in browser-less environment like node.js
18
18
  // to avoid compiler errors this monkey patch is used
19
19
  // see more details in https://github.com/DefinitelyTyped/DefinitelyTyped/issues/11351
20
- interface Event { } // tslint:disable-line no-empty-interface
21
- interface Document { } // tslint:disable-line no-empty-interface
20
+ interface Event {} // tslint:disable-line no-empty-interface
21
+ interface Document {} // tslint:disable-line no-empty-interface
22
22
 
23
23
  declare namespace Sinon {
24
- interface SinonSpyCallApi {
24
+ type MatchArguments<T> = {
25
+ [K in keyof T]: SinonMatcher | (T[K] extends object ? MatchArguments<T[K]> : never) | T[K];
26
+ };
27
+
28
+ interface SinonSpyCallApi<TArgs extends any[] = any[], TReturnValue = any> {
25
29
  // Properties
26
30
  /**
27
31
  * Array of received arguments.
28
32
  */
29
- args: any[];
33
+ args: TArgs;
30
34
 
31
35
  // Methods
32
36
  /**
@@ -41,11 +45,11 @@ declare namespace Sinon {
41
45
  * so a call that received the provided arguments (in the same spots) and possibly others as well will return true.
42
46
  * @param args
43
47
  */
44
- calledWith(...args: any[]): boolean;
48
+ calledWith(...args: Partial<MatchArguments<TArgs>>): boolean;
45
49
  /**
46
50
  * Returns true if spy was called at least once with the provided arguments and no others.
47
51
  */
48
- calledWithExactly(...args: any[]): boolean;
52
+ calledWithExactly(...args: MatchArguments<TArgs>): boolean;
49
53
  /**
50
54
  * Returns true if spy/stub was called the new operator.
51
55
  * Beware that this is inferred based on the value of the this object and the spy function’s prototype,
@@ -56,31 +60,31 @@ declare namespace Sinon {
56
60
  * Returns true if spy was called at exactly once with the provided arguments.
57
61
  * @param args
58
62
  */
59
- calledOnceWith(...args: any[]): boolean;
60
- calledOnceWithExactly(...args: any[]): boolean;
63
+ calledOnceWith(...args: MatchArguments<TArgs>): boolean;
64
+ calledOnceWithExactly(...args: MatchArguments<TArgs>): boolean;
61
65
  /**
62
66
  * Returns true if spy was called with matching arguments (and possibly others).
63
67
  * This behaves the same as spy.calledWith(sinon.match(arg1), sinon.match(arg2), ...).
64
68
  * @param args
65
69
  */
66
- calledWithMatch(...args: any[]): boolean;
70
+ calledWithMatch(...args: TArgs): boolean;
67
71
  /**
68
72
  * Returns true if call did not receive provided arguments.
69
73
  * @param args
70
74
  */
71
- notCalledWith(...args: any[]): boolean;
75
+ notCalledWith(...args: MatchArguments<TArgs>): boolean;
72
76
  /**
73
77
  * Returns true if call did not receive matching arguments.
74
78
  * This behaves the same as spyCall.notCalledWith(sinon.match(arg1), sinon.match(arg2), ...).
75
79
  * @param args
76
80
  */
77
- notCalledWithMatch(...args: any[]): boolean;
81
+ notCalledWithMatch(...args: TArgs): boolean;
78
82
  /**
79
83
  * Returns true if spy returned the provided value at least once.
80
84
  * Uses deep comparison for objects and arrays. Use spy.returned(sinon.match.same(obj)) for strict comparison (see matchers).
81
85
  * @param value
82
86
  */
83
- returned(value: any): boolean;
87
+ returned(value: TReturnValue | SinonMatcher): boolean;
84
88
  /**
85
89
  * Returns true if spy threw an exception at least once.
86
90
  */
@@ -121,7 +125,8 @@ declare namespace Sinon {
121
125
  yieldToOn(property: string, obj: any, ...args: any[]): void;
122
126
  }
123
127
 
124
- interface SinonSpyCall extends SinonSpyCallApi {
128
+ interface SinonSpyCall<TArgs extends any[] = any[], TReturnValue = any>
129
+ extends SinonSpyCallApi<TArgs, TReturnValue> {
125
130
  /**
126
131
  * The call’s this value.
127
132
  */
@@ -133,12 +138,18 @@ declare namespace Sinon {
133
138
  /**
134
139
  * Return value.
135
140
  */
136
- returnValue: any;
141
+ returnValue: TReturnValue;
137
142
  /**
138
143
  * This property is a convenience for a call’s callback.
139
144
  * When the last argument in a call is a Function, then callback will reference that. Otherwise it will be undefined.
140
145
  */
141
146
  callback: Function | undefined;
147
+
148
+ /**
149
+ * This property is a convenience for the first argument of the call.
150
+ */
151
+ firstArg: any;
152
+
142
153
  /**
143
154
  * This property is a convenience for the last argument of the call.
144
155
  */
@@ -147,16 +158,21 @@ declare namespace Sinon {
147
158
  /**
148
159
  * Returns true if the spy call occurred before another spy call.
149
160
  * @param call
161
+ *
150
162
  */
151
- calledBefore(call: SinonSpyCall): boolean;
163
+ calledBefore(call: SinonSpyCall<any>): boolean;
152
164
  /**
153
165
  * Returns true if the spy call occurred after another spy call.
154
166
  * @param call
155
167
  */
156
- calledAfter(call: SinonSpyCall): boolean;
168
+ calledAfter(call: SinonSpyCall<any>): boolean;
157
169
  }
158
170
 
159
- interface SinonSpy extends SinonSpyCallApi {
171
+ interface SinonSpy<TArgs extends any[] = any[], TReturnValue = any>
172
+ extends Pick<
173
+ SinonSpyCallApi<TArgs, TReturnValue>,
174
+ Exclude<keyof SinonSpyCallApi<TArgs, TReturnValue>, 'args'>
175
+ > {
160
176
  // Properties
161
177
  /**
162
178
  * The number of recorded calls.
@@ -185,19 +201,19 @@ declare namespace Sinon {
185
201
  /**
186
202
  * The first call
187
203
  */
188
- firstCall: SinonSpyCall;
204
+ firstCall: SinonSpyCall<TArgs, TReturnValue>;
189
205
  /**
190
206
  * The second call
191
207
  */
192
- secondCall: SinonSpyCall;
208
+ secondCall: SinonSpyCall<TArgs, TReturnValue>;
193
209
  /**
194
210
  * The third call
195
211
  */
196
- thirdCall: SinonSpyCall;
212
+ thirdCall: SinonSpyCall<TArgs, TReturnValue>;
197
213
  /**
198
214
  * The last call
199
215
  */
200
- lastCall: SinonSpyCall;
216
+ lastCall: SinonSpyCall<TArgs, TReturnValue>;
201
217
  /**
202
218
  * Array of this objects, spy.thisValues[0] is the this object for the first call.
203
219
  */
@@ -205,7 +221,7 @@ declare namespace Sinon {
205
221
  /**
206
222
  * Array of arguments received, spy.args[0] is an array of arguments received in the first call.
207
223
  */
208
- args: any[][];
224
+ args: TArgs[];
209
225
  /**
210
226
  * Array of exception objects thrown, spy.exceptions[0] is the exception thrown by the first call.
211
227
  * If the call did not throw an error, the value at the call’s location in .exceptions will be undefined.
@@ -215,36 +231,43 @@ declare namespace Sinon {
215
231
  * Array of return values, spy.returnValues[0] is the return value of the first call.
216
232
  * If the call did not explicitly return a value, the value at the call’s location in .returnValues will be undefined.
217
233
  */
218
- returnValues: any[];
234
+ returnValues: TReturnValue[];
235
+
236
+ /**
237
+ * Holds a reference to the original method/function this stub has wrapped.
238
+ */
239
+ wrappedMethod: (...args: TArgs) => TReturnValue;
219
240
 
220
241
  // Methods
221
- (...args: any[]): any;
242
+ (...args: TArgs): TReturnValue;
243
+
222
244
  /**
223
245
  * Returns true if the spy was called before @param anotherSpy
224
246
  * @param anotherSpy
225
247
  */
226
- calledBefore(anotherSpy: SinonSpy): boolean;
248
+ calledBefore(anotherSpy: SinonSpy<any>): boolean;
227
249
  /**
228
250
  * Returns true if the spy was called after @param anotherSpy
229
251
  * @param anotherSpy
230
252
  */
231
- calledAfter(anotherSpy: SinonSpy): boolean;
253
+ calledAfter(anotherSpy: SinonSpy<any>): boolean;
232
254
  /**
233
255
  * Returns true if spy was called before @param anotherSpy, and no spy calls occurred between spy and @param anotherSpy.
234
256
  * @param anotherSpy
235
257
  */
236
- calledImmediatelyBefore(anotherSpy: SinonSpy): boolean;
258
+ calledImmediatelyBefore(anotherSpy: SinonSpy<any>): boolean;
237
259
  /**
238
260
  * Returns true if spy was called after @param anotherSpy, and no spy calls occurred between @param anotherSpy and spy.
239
261
  * @param anotherSpy
240
262
  */
241
- calledImmediatelyAfter(anotherSpy: SinonSpy): boolean;
263
+ calledImmediatelyAfter(anotherSpy: SinonSpy<any>): boolean;
264
+
242
265
  /**
243
266
  * Creates a spy that only records calls when the received arguments match those passed to withArgs.
244
267
  * This is useful to be more expressive in your assertions, where you can access the spy with the same call.
245
268
  * @param args Expected args
246
269
  */
247
- withArgs(...args: any[]): SinonSpy;
270
+ withArgs(...args: MatchArguments<TArgs>): SinonSpy<TArgs, TReturnValue>;
248
271
  /**
249
272
  * Returns true if the spy was always called with @param obj as this.
250
273
  * @param obj
@@ -253,29 +276,29 @@ declare namespace Sinon {
253
276
  /**
254
277
  * Returns true if spy was always called with the provided arguments (and possibly others).
255
278
  */
256
- alwaysCalledWith(...args: any[]): boolean;
279
+ alwaysCalledWith(...args: MatchArguments<TArgs>): boolean;
257
280
  /**
258
281
  * Returns true if spy was always called with the exact provided arguments.
259
282
  * @param args
260
283
  */
261
- alwaysCalledWithExactly(...args: any[]): boolean;
284
+ alwaysCalledWithExactly(...args: MatchArguments<TArgs>): boolean;
262
285
  /**
263
286
  * Returns true if spy was always called with matching arguments (and possibly others).
264
287
  * This behaves the same as spy.alwaysCalledWith(sinon.match(arg1), sinon.match(arg2), ...).
265
288
  * @param args
266
289
  */
267
- alwaysCalledWithMatch(...args: any[]): boolean;
290
+ alwaysCalledWithMatch(...args: TArgs): boolean;
268
291
  /**
269
292
  * Returns true if the spy/stub was never called with the provided arguments.
270
293
  * @param args
271
294
  */
272
- neverCalledWith(...args: any[]): boolean;
295
+ neverCalledWith(...args: MatchArguments<TArgs>): boolean;
273
296
  /**
274
297
  * Returns true if the spy/stub was never called with matching arguments.
275
298
  * This behaves the same as spy.neverCalledWith(sinon.match(arg1), sinon.match(arg2), ...).
276
299
  * @param args
277
300
  */
278
- neverCalledWithMatch(...args: any[]): boolean;
301
+ neverCalledWithMatch(...args: TArgs): boolean;
279
302
  /**
280
303
  * Returns true if spy always threw an exception.
281
304
  */
@@ -298,22 +321,22 @@ declare namespace Sinon {
298
321
  * If the stub was never called with a function argument, yield throws an error.
299
322
  * Returns an Array with all callbacks return values in the order they were called, if no error is thrown.
300
323
  */
301
- invokeCallback(...args: any[]): void;
324
+ invokeCallback(...args: TArgs): void;
302
325
  /**
303
326
  * Set the displayName of the spy or stub.
304
327
  * @param name
305
328
  */
306
- named(name: string): SinonSpy;
329
+ named(name: string): SinonSpy<TArgs, TReturnValue>;
307
330
  /**
308
331
  * Returns the nth call.
309
332
  * Accessing individual calls helps with more detailed behavior verification when the spy is called more than once.
310
- * @param n
333
+ * @param n Zero based index of the spy call.
311
334
  */
312
- getCall(n: number): SinonSpyCall;
335
+ getCall(n: number): SinonSpyCall<TArgs, TReturnValue>;
313
336
  /**
314
337
  * Returns an Array of all calls recorded by the spy.
315
338
  */
316
- getCalls(): SinonSpyCall[];
339
+ getCalls(): Array<SinonSpyCall<TArgs, TReturnValue>>;
317
340
  /**
318
341
  * Resets the state of a spy.
319
342
  */
@@ -345,7 +368,7 @@ declare namespace Sinon {
345
368
  /**
346
369
  * Spies on the provided function
347
370
  */
348
- (func: Function): SinonSpy;
371
+ <F extends (...args: any[]) => any>(func: F): SinonSpy<Parameters<F>, ReturnType<F>>;
349
372
  /**
350
373
  * Creates a spy for object.method and replaces the original method with the spy.
351
374
  * An exception is thrown if the property is not already a function.
@@ -353,10 +376,17 @@ declare namespace Sinon {
353
376
  * The original method can be restored by calling object.method.restore().
354
377
  * The returned spy is the function object which replaced the original method. spy === object.method.
355
378
  */
356
- <T>(obj: T, method: keyof T, types?: string[]): SinonSpy;
379
+ <T, K extends keyof T>(obj: T, method: K): T[K] extends (...args: infer TArgs) => infer TReturnValue
380
+ ? SinonSpy<TArgs, TReturnValue>
381
+ : SinonSpy;
382
+
383
+ <T, K extends keyof T>(obj: T, method: K, types: Array<'get' | 'set'>): PropertyDescriptor & {
384
+ get: SinonSpy<[], T[K]>;
385
+ set: SinonSpy<[T[K]], void>;
386
+ };
357
387
  }
358
388
 
359
- interface SinonStub extends SinonSpy {
389
+ interface SinonStub<TArgs extends any[] = any[], TReturnValue = any> extends SinonSpy<TArgs, TReturnValue> {
360
390
  /**
361
391
  * Resets the stub’s behaviour to the default behaviour
362
392
  * You can reset behaviour of all stubs using sinon.resetBehavior()
@@ -374,13 +404,13 @@ declare namespace Sinon {
374
404
  * Causes the stub to return promises using a specific Promise library instead of the global one when using stub.rejects or stub.resolves.
375
405
  * Returns the stub to allow chaining.
376
406
  */
377
- usingPromise(promiseLibrary: any): SinonStub;
407
+ usingPromise(promiseLibrary: any): SinonStub<TArgs, TReturnValue>;
378
408
 
379
409
  /**
380
410
  * Makes the stub return the provided @param obj value.
381
411
  * @param obj
382
412
  */
383
- returns(obj: any): SinonStub;
413
+ returns(obj: TReturnValue): SinonStub<TArgs, TReturnValue>;
384
414
  /**
385
415
  * Causes the stub to return the argument at the provided @param index.
386
416
  * stub.returnsArg(0); causes the stub to return the first argument.
@@ -388,12 +418,12 @@ declare namespace Sinon {
388
418
  * starting from sinon@6.1.2, a TypeError will be thrown.
389
419
  * @param index
390
420
  */
391
- returnsArg(index: number): SinonStub;
421
+ returnsArg(index: number): SinonStub<TArgs, TReturnValue>;
392
422
  /**
393
423
  * Causes the stub to return its this value.
394
424
  * Useful for stubbing jQuery-style fluent APIs.
395
425
  */
396
- returnsThis(): SinonStub;
426
+ returnsThis(): SinonStub<TArgs, TReturnValue>;
397
427
  /**
398
428
  * Causes the stub to return a Promise which resolves to the provided value.
399
429
  * When constructing the Promise, sinon uses the Promise.resolve method.
@@ -401,26 +431,28 @@ declare namespace Sinon {
401
431
  * The Promise library can be overwritten using the usingPromise method.
402
432
  * Since sinon@2.0.0
403
433
  */
404
- resolves(value?: any): SinonStub;
434
+ resolves(
435
+ value?: TReturnValue extends PromiseLike<infer TResolveValue> ? TResolveValue : any,
436
+ ): SinonStub<TArgs, TReturnValue>;
405
437
  /**
406
438
  * Causes the stub to return a Promise which resolves to the argument at the provided index.
407
439
  * stub.resolvesArg(0); causes the stub to return a Promise which resolves to the first argument.
408
440
  * If the argument at the provided index is not available, a TypeError will be thrown.
409
441
  */
410
- resolvesArg(index: number): SinonStub;
442
+ resolvesArg(index: number): SinonStub<TArgs, TReturnValue>;
411
443
  /**
412
444
  * Causes the stub to return a Promise which resolves to its this value.
413
445
  */
414
- resolvesThis(): SinonStub;
446
+ resolvesThis(): SinonStub<TArgs, TReturnValue>;
415
447
  /**
416
448
  * Causes the stub to throw an exception (Error).
417
449
  * @param type
418
450
  */
419
- throws(type?: string): SinonStub;
451
+ throws(type?: string): SinonStub<TArgs, TReturnValue>;
420
452
  /**
421
453
  * Causes the stub to throw the provided exception object.
422
454
  */
423
- throws(obj: any): SinonStub;
455
+ throws(obj: any): SinonStub<TArgs, TReturnValue>;
424
456
  /**
425
457
  * Causes the stub to throw the argument at the provided index.
426
458
  * stub.throwsArg(0); causes the stub to throw the first argument as the exception.
@@ -428,9 +460,9 @@ declare namespace Sinon {
428
460
  * Since sinon@2.3.0
429
461
  * @param index
430
462
  */
431
- throwsArg(index: number): SinonStub;
432
- throwsException(type?: string): SinonStub;
433
- throwsException(obj: any): SinonStub;
463
+ throwsArg(index: number): SinonStub<TArgs, TReturnValue>;
464
+ throwsException(type?: string): SinonStub<TArgs, TReturnValue>;
465
+ throwsException(obj: any): SinonStub<TArgs, TReturnValue>;
434
466
  /**
435
467
  * Causes the stub to return a Promise which rejects with an exception (Error).
436
468
  * When constructing the Promise, sinon uses the Promise.reject method.
@@ -438,53 +470,53 @@ declare namespace Sinon {
438
470
  * The Promise library can be overwritten using the usingPromise method.
439
471
  * Since sinon@2.0.0
440
472
  */
441
- rejects(): SinonStub;
473
+ rejects(): SinonStub<TArgs, TReturnValue>;
442
474
  /**
443
475
  * Causes the stub to return a Promise which rejects with an exception of the provided type.
444
476
  * Since sinon@2.0.0
445
477
  */
446
- rejects(errorType: string): SinonStub;
478
+ rejects(errorType: string): SinonStub<TArgs, TReturnValue>;
447
479
  /**
448
480
  * Causes the stub to return a Promise which rejects with the provided exception object.
449
481
  * Since sinon@2.0.0
450
482
  */
451
- rejects(value: any): SinonStub;
483
+ rejects(value: any): SinonStub<TArgs, TReturnValue>;
452
484
  /**
453
485
  * Causes the stub to call the argument at the provided index as a callback function.
454
486
  * stub.callsArg(0); causes the stub to call the first argument as a callback.
455
487
  * If the argument at the provided index is not available or is not a function, a TypeError will be thrown.
456
488
  */
457
- callsArg(index: number): SinonStub;
489
+ callsArg(index: number): SinonStub<TArgs, TReturnValue>;
458
490
  /**
459
491
  * Causes the original method wrapped into the stub to be called when none of the conditional stubs are matched.
460
492
  */
461
- callThrough(): SinonStub;
493
+ callThrough(): SinonStub<TArgs, TReturnValue>;
462
494
  /**
463
495
  * Like stub.callsArg(index); but with an additional parameter to pass the this context.
464
496
  * @param index
465
497
  * @param context
466
498
  */
467
- callsArgOn(index: number, context: any): SinonStub;
499
+ callsArgOn(index: number, context: any): SinonStub<TArgs, TReturnValue>;
468
500
  /**
469
501
  * Like callsArg, but with arguments to pass to the callback.
470
502
  * @param index
471
503
  * @param args
472
504
  */
473
- callsArgWith(index: number, ...args: any[]): SinonStub;
505
+ callsArgWith(index: number, ...args: any[]): SinonStub<TArgs, TReturnValue>;
474
506
  /**
475
507
  * Like above but with an additional parameter to pass the this context.
476
508
  * @param index
477
509
  * @param context
478
510
  * @param args
479
511
  */
480
- callsArgOnWith(index: number, context: any, ...args: any[]): SinonStub;
512
+ callsArgOnWith(index: number, context: any, ...args: any[]): SinonStub<TArgs, TReturnValue>;
481
513
  /**
482
514
  * Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
483
515
  * In Node environment the callback is deferred with process.nextTick.
484
516
  * In a browser the callback is deferred with setTimeout(callback, 0).
485
517
  * @param index
486
518
  */
487
- callsArgAsync(index: number): SinonStub;
519
+ callsArgAsync(index: number): SinonStub<TArgs, TReturnValue>;
488
520
  /**
489
521
  * Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
490
522
  * In Node environment the callback is deferred with process.nextTick.
@@ -492,91 +524,91 @@ declare namespace Sinon {
492
524
  * @param index
493
525
  * @param context
494
526
  */
495
- callsArgOnAsync(index: number, context: any): SinonStub;
527
+ callsArgOnAsync(index: number, context: any): SinonStub<TArgs, TReturnValue>;
496
528
  /**
497
529
  * Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
498
530
  * In Node environment the callback is deferred with process.nextTick.
499
531
  * In a browser the callback is deferred with setTimeout(callback, 0).
500
532
  */
501
- callsArgWithAsync(index: number, ...args: any[]): SinonStub;
533
+ callsArgWithAsync(index: number, ...args: any[]): SinonStub<TArgs, TReturnValue>;
502
534
  /**
503
535
  * Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
504
536
  * In Node environment the callback is deferred with process.nextTick.
505
537
  * In a browser the callback is deferred with setTimeout(callback, 0).
506
538
  */
507
- callsArgOnWithAsync(index: number, context: any, ...args: any[]): SinonStub;
539
+ callsArgOnWithAsync(index: number, context: any, ...args: any[]): SinonStub<TArgs, TReturnValue>;
508
540
  /**
509
541
  * Makes the stub call the provided @param func when invoked.
510
542
  * @param func
511
543
  */
512
- callsFake(func: (...args: any[]) => any): SinonStub;
544
+ callsFake(func: (...args: TArgs) => TReturnValue): SinonStub<TArgs, TReturnValue>;
513
545
  /**
514
546
  * Replaces a new getter for this stub.
515
547
  */
516
- get(func: () => any): SinonStub;
548
+ get(func: () => any): SinonStub<TArgs, TReturnValue>;
517
549
  /**
518
550
  * Defines a new setter for this stub.
519
551
  * @param func
520
552
  */
521
- set(func: (v: any) => void): SinonStub;
553
+ set(func: (v: any) => void): SinonStub<TArgs, TReturnValue>;
522
554
  /**
523
555
  * Defines the behavior of the stub on the @param n call. Useful for testing sequential interactions.
524
556
  * There are methods onFirstCall, onSecondCall,onThirdCall to make stub definitions read more naturally.
525
557
  * onCall can be combined with all of the behavior defining methods in this section. In particular, it can be used together with withArgs.
526
558
  * @param n
527
559
  */
528
- onCall(n: number): SinonStub;
560
+ onCall(n: number): SinonStub<TArgs, TReturnValue>;
529
561
  /**
530
562
  * Alias for stub.onCall(0);
531
563
  */
532
- onFirstCall(): SinonStub;
564
+ onFirstCall(): SinonStub<TArgs, TReturnValue>;
533
565
  /**
534
566
  * Alias for stub.onCall(1);
535
567
  */
536
- onSecondCall(): SinonStub;
568
+ onSecondCall(): SinonStub<TArgs, TReturnValue>;
537
569
  /**
538
570
  * Alias for stub.onCall(2);
539
571
  */
540
- onThirdCall(): SinonStub;
572
+ onThirdCall(): SinonStub<TArgs, TReturnValue>;
541
573
  /**
542
574
  * Defines a new value for this stub.
543
575
  * @param val
544
576
  */
545
- value(val: any): SinonStub;
577
+ value(val: any): SinonStub<TArgs, TReturnValue>;
546
578
  /**
547
579
  * Set the displayName of the spy or stub.
548
580
  * @param name
549
581
  */
550
- named(name: string): SinonStub;
582
+ named(name: string): SinonStub<TArgs, TReturnValue>;
551
583
  /**
552
584
  * Similar to callsArg.
553
585
  * Causes the stub to call the first callback it receives with the provided arguments (if any).
554
586
  * If a method accepts more than one callback, you need to use callsArg to have the stub invoke other callbacks than the first one.
555
587
  */
556
- yields(...args: any[]): SinonStub;
588
+ yields(...args: any[]): SinonStub<TArgs, TReturnValue>;
557
589
  /**
558
590
  * Like above but with an additional parameter to pass the this context.
559
591
  */
560
- yieldsOn(context: any, ...args: any[]): SinonStub;
561
- yieldsRight(...args: any[]): SinonStub;
592
+ yieldsOn(context: any, ...args: any[]): SinonStub<TArgs, TReturnValue>;
593
+ yieldsRight(...args: any[]): SinonStub<TArgs, TReturnValue>;
562
594
  /**
563
595
  * Causes the spy to invoke a callback passed as a property of an object to the spy.
564
596
  * Like yields, yieldsTo grabs the first matching argument, finds the callback and calls it with the (optional) arguments.
565
597
  * @param property
566
598
  * @param args
567
599
  */
568
- yieldsTo(property: string, ...args: any[]): SinonStub;
600
+ yieldsTo(property: string, ...args: any[]): SinonStub<TArgs, TReturnValue>;
569
601
  /**
570
602
  * Like above but with an additional parameter to pass the this context.
571
603
  */
572
- yieldsToOn(property: string, context: any, ...args: any[]): SinonStub;
604
+ yieldsToOn(property: string, context: any, ...args: any[]): SinonStub<TArgs, TReturnValue>;
573
605
  /**
574
606
  * Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
575
607
  * In Node environment the callback is deferred with process.nextTick.
576
608
  * In a browser the callback is deferred with setTimeout(callback, 0).
577
609
  * @param args
578
610
  */
579
- yieldsAsync(...args: any[]): SinonStub;
611
+ yieldsAsync(...args: any[]): SinonStub<TArgs, TReturnValue>;
580
612
  /**
581
613
  * Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
582
614
  * In Node environment the callback is deferred with process.nextTick.
@@ -584,7 +616,7 @@ declare namespace Sinon {
584
616
  * @param context
585
617
  * @param args
586
618
  */
587
- yieldsOnAsync(context: any, ...args: any[]): SinonStub;
619
+ yieldsOnAsync(context: any, ...args: any[]): SinonStub<TArgs, TReturnValue>;
588
620
  /**
589
621
  * Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
590
622
  * In Node environment the callback is deferred with process.nextTick.
@@ -592,7 +624,7 @@ declare namespace Sinon {
592
624
  * @param property
593
625
  * @param args
594
626
  */
595
- yieldsToAsync(property: string, ...args: any[]): SinonStub;
627
+ yieldsToAsync(property: string, ...args: any[]): SinonStub<TArgs, TReturnValue>;
596
628
  /**
597
629
  * Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
598
630
  * In Node environment the callback is deferred with process.nextTick.
@@ -601,21 +633,26 @@ declare namespace Sinon {
601
633
  * @param context
602
634
  * @param args
603
635
  */
604
- yieldsToOnAsync(property: string, context: any, ...args: any[]): SinonStub;
636
+ yieldsToOnAsync(property: string, context: any, ...args: any[]): SinonStub<TArgs, TReturnValue>;
605
637
  /**
606
638
  * Stubs the method only for the provided arguments.
607
639
  * This is useful to be more expressive in your assertions, where you can access the spy with the same call.
608
640
  * It is also useful to create a stub that can act differently in response to different arguments.
609
641
  * @param args
610
642
  */
611
- withArgs(...args: any[]): SinonStub;
643
+ withArgs(...args: MatchArguments<TArgs>): SinonStub<TArgs, TReturnValue>;
612
644
  }
613
645
 
614
646
  interface SinonStubStatic {
647
+ /* tslint:disable:no-unnecessary-generics */
648
+
615
649
  /**
616
650
  * Creates an anonymous stub function
617
651
  */
618
- (): SinonStub;
652
+ <TArgs extends any[] = any[], R = any>(): SinonStub<TArgs, R>;
653
+
654
+ /* tslint:enable:no-unnecessary-generics */
655
+
619
656
  /**
620
657
  * Stubs all the object’s methods.
621
658
  * 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).
@@ -628,7 +665,9 @@ declare namespace Sinon {
628
665
  * An exception is thrown if the property is not already a function.
629
666
  * The original function can be restored by calling object.method.restore(); (or stub.restore();).
630
667
  */
631
- <T>(obj: T, method: keyof T): SinonStub;
668
+ <T, K extends keyof T>(obj: T, method: K): T[K] extends (...args: infer TArgs) => infer TReturnValue
669
+ ? SinonStub<TArgs, TReturnValue>
670
+ : SinonStub;
632
671
  }
633
672
 
634
673
  interface SinonExpectation extends SinonStub {
@@ -725,84 +764,17 @@ declare namespace Sinon {
725
764
  (obj: any): SinonMock;
726
765
  }
727
766
 
728
- type SinonTimerId = number | { id: number };
729
-
730
- interface SinonFakeTimers {
731
- now: number;
732
- loopLimit: number;
733
-
734
- setTimeout(callback: (...args: any[]) => void, timeout: number, ...args: any[]): SinonTimerId;
735
- clearTimeout(id: SinonTimerId): void;
736
-
737
- setInterval(callback: (...args: any[]) => void, timeout: number, ...args: any[]): SinonTimerId;
738
- clearInterval(id: SinonTimerId): void;
739
-
740
- setImmediate(callback: (...args: any[]) => void, ...args: any[]): SinonTimerId;
741
- clearImmediate(id: SinonTimerId): void;
742
-
743
- requestAnimationFrame(callback: (time: number) => void): SinonTimerId;
744
- cancelAnimationFrame(id: SinonTimerId): void;
745
-
746
- nextTick(callback: (...args: any[]) => void, ...args: any[]): void;
747
- queueMicrotask(callback: () => void): void;
748
-
749
- requestIdleCallback(func: (...args: any[]) => void, timeout?: number, ...args: any[]): SinonTimerId;
750
- cancelIdleCallback(timerId: SinonTimerId): void;
751
-
752
- /**
753
- * Tick the clock ahead time milliseconds.
754
- * Causes all timers scheduled within the affected time range to be called.
755
- * time may be the number of milliseconds to advance the clock by or a human-readable string.
756
- * Valid string formats are “08” for eight seconds, “01:00” for one minute and “02:34:10” for two hours, 34 minutes and ten seconds.
757
- * time may be negative, which causes the clock to change but won’t fire any callbacks.
758
- * @param ms
759
- */
760
- tick(ms: number | string): number;
761
- /**
762
- * Advances the clock to the the moment of the first scheduled timer, firing it.
763
- */
764
- next(): number;
765
- /**
766
- * This runs all pending timers until there are none remaining. If new timers are added while it is executing they will be run as well.
767
- * This makes it easier to run asynchronous tests to completion without worrying about the number of timers they use, or the delays in those timers.
768
- */
769
- runAll(): number;
770
- runToLast(): number;
771
- reset(): void;
772
- runMicrotasks(): void;
773
- runToFrame(): number;
774
-
775
- Date(): Date;
776
- Date(year: number): Date;
777
- Date(year: number, month: number): Date;
778
- Date(year: number, month: number, day: number): Date;
779
- Date(year: number, month: number, day: number, hour: number): Date;
780
- Date(year: number, month: number, day: number, hour: number, minute: number): Date;
781
- Date(year: number, month: number, day: number, hour: number, minute: number, second: number): Date;
782
- Date(year: number, month: number, day: number, hour: number, minute: number, second: number, ms: number): Date;
783
-
784
- /**
785
- * Restore the faked methods.
786
- * Call in e.g. tearDown.
787
- */
788
- restore(): void;
789
- uninstall(): void;
790
-
791
- /**
792
- * Simulate the user changing the system clock while your program is running. It changes the 'now' timestamp
793
- * without affecting timers, intervals or immediates.
794
- * @param now The new 'now' in unix milliseconds
795
- */
796
- setSystemTime(now: number): void;
797
- /**
798
- * Simulate the user changing the system clock while your program is running. It changes the 'now' timestamp
799
- * without affecting timers, intervals or immediates.
800
- * @param now The new 'now' as a JavaScript Date
801
- */
802
- setSystemTime(date: Date): void;
767
+ type SinonTimerId = FakeTimers.TimerId;
803
768
 
804
- countTimers(): number;
805
- }
769
+ type SinonFakeTimers = FakeTimers.InstalledMethods &
770
+ FakeTimers.NodeClock &
771
+ FakeTimers.BrowserClock & {
772
+ /**
773
+ * Restore the faked methods.
774
+ * Call in e.g. tearDown.
775
+ */
776
+ restore(): void;
777
+ };
806
778
 
807
779
  interface SinonFakeTimersConfig {
808
780
  now: number | Date;
@@ -902,7 +874,7 @@ declare namespace Sinon {
902
874
  }
903
875
 
904
876
  interface SinonFakeXMLHttpRequestStatic {
905
- new(): SinonFakeXMLHttpRequest;
877
+ new (): SinonFakeXMLHttpRequest;
906
878
  /**
907
879
  * Default false.
908
880
  * When set to true, Sinon will check added filters if certain requests should be “unfaked”
@@ -914,7 +886,9 @@ declare namespace Sinon {
914
886
  * If the filter returns true, the request will not be faked.
915
887
  * @param filter
916
888
  */
917
- addFilter(filter: (method: string, url: string, async: boolean, username: string, password: string) => boolean): void;
889
+ addFilter(
890
+ filter: (method: string, url: string, async: boolean, username: string, password: string) => boolean,
891
+ ): void;
918
892
  /**
919
893
  * By assigning a function to the onCreate property of the returned object from useFakeXMLHttpRequest()
920
894
  * you can subscribe to newly created FakeXMLHttpRequest objects. See below for the fake xhr object API.
@@ -1087,127 +1061,155 @@ declare namespace Sinon {
1087
1061
  pass(assertion: any): void; // Overridable
1088
1062
 
1089
1063
  // Methods
1064
+
1090
1065
  /**
1091
1066
  * Passes if spy was never called
1092
1067
  * @param spy
1093
1068
  */
1094
- notCalled(spy: SinonSpy): void;
1069
+ notCalled(spy: SinonSpy<any>): void;
1095
1070
  /**
1096
1071
  * Passes if spy was called at least once.
1097
1072
  */
1098
- called(spy: SinonSpy): void;
1073
+ called(spy: SinonSpy<any>): void;
1099
1074
  /**
1100
1075
  * Passes if spy was called once and only once.
1101
1076
  */
1102
- calledOnce(spy: SinonSpy): void;
1077
+ calledOnce(spy: SinonSpy<any>): void;
1103
1078
  /**
1104
1079
  * Passes if spy was called exactly twice.
1105
1080
  */
1106
- calledTwice(spy: SinonSpy): void;
1081
+ calledTwice(spy: SinonSpy<any>): void;
1107
1082
  /**
1108
1083
  * Passes if spy was called exactly three times.
1109
1084
  */
1110
- calledThrice(spy: SinonSpy): void;
1085
+ calledThrice(spy: SinonSpy<any>): void;
1111
1086
  /**
1112
1087
  * Passes if spy was called exactly num times.
1113
1088
  */
1114
- callCount(spy: SinonSpy, count: number): void;
1089
+ callCount(spy: SinonSpy<any>, count: number): void;
1115
1090
  /**
1116
1091
  * Passes if provided spies were called in the specified order.
1117
1092
  * @param spies
1118
1093
  */
1119
- callOrder(...spies: SinonSpy[]): void;
1094
+ callOrder(...spies: Array<SinonSpy<any>>): void;
1120
1095
  /**
1121
1096
  * Passes if spy was ever called with obj as its this value.
1122
1097
  * It’s possible to assert on a dedicated spy call: sinon.assert.calledOn(spy.firstCall, arg1, arg2, ...);.
1123
1098
  */
1124
- calledOn(spyOrSpyCall: SinonSpy | SinonSpyCall, obj: any): void;
1099
+ calledOn(spyOrSpyCall: SinonSpy<any> | SinonSpyCall<any>, obj: any): void;
1125
1100
  /**
1126
1101
  * Passes if spy was always called with obj as its this value.
1127
1102
  */
1128
- alwaysCalledOn(spy: SinonSpy, obj: any): void;
1103
+ alwaysCalledOn(spy: SinonSpy<any>, obj: any): void;
1104
+
1129
1105
  /**
1130
1106
  * Passes if spy was called with the provided arguments.
1131
1107
  * It’s possible to assert on a dedicated spy call: sinon.assert.calledWith(spy.firstCall, arg1, arg2, ...);.
1132
1108
  * @param spyOrSpyCall
1133
1109
  * @param args
1134
1110
  */
1135
- calledWith(spyOrSpyCall: SinonSpy | SinonSpyCall, ...args: any[]): void;
1111
+ calledWith<TArgs extends any[]>(
1112
+ spyOrSpyCall: SinonSpy<TArgs> | SinonSpyCall<TArgs>,
1113
+ ...args: MatchArguments<TArgs>
1114
+ ): void;
1136
1115
  /**
1137
1116
  * Passes if spy was always called with the provided arguments.
1138
1117
  * @param spy
1139
1118
  * @param args
1140
1119
  */
1141
- alwaysCalledWith(spy: SinonSpy, ...args: any[]): void;
1120
+ alwaysCalledWith<TArgs extends any[]>(spy: SinonSpy<TArgs>, ...args: MatchArguments<TArgs>): void;
1142
1121
  /**
1143
1122
  * Passes if spy was never called with the provided arguments.
1144
1123
  * @param spy
1145
1124
  * @param args
1146
1125
  */
1147
- neverCalledWith(spy: SinonSpy, ...args: any[]): void;
1126
+ neverCalledWith<TArgs extends any[]>(spy: SinonSpy<TArgs>, ...args: MatchArguments<TArgs>): void;
1148
1127
  /**
1149
1128
  * Passes if spy was called with the provided arguments and no others.
1150
1129
  * It’s possible to assert on a dedicated spy call: sinon.assert.calledWithExactly(spy.getCall(1), arg1, arg2, ...);.
1151
1130
  * @param spyOrSpyCall
1152
1131
  * @param args
1153
1132
  */
1154
- calledWithExactly(spyOrSpyCall: SinonSpy | SinonSpyCall, ...args: any[]): void;
1133
+ calledWithExactly<TArgs extends any[]>(
1134
+ spyOrSpyCall: SinonSpy<TArgs> | SinonSpyCall<TArgs>,
1135
+ ...args: MatchArguments<TArgs>
1136
+ ): void;
1137
+ /**
1138
+ * Passes if spy was called at exactly once with the provided arguments and no others.
1139
+ * @param spyOrSpyCall
1140
+ * @param args
1141
+ */
1142
+ calledOnceWithExactly<TArgs extends any[]>(
1143
+ spyOrSpyCall: SinonSpy<TArgs> | SinonSpyCall<TArgs>,
1144
+ ...args: MatchArguments<TArgs>
1145
+ ): void;
1155
1146
  /**
1156
1147
  * Passes if spy was always called with the provided arguments and no others.
1157
1148
  */
1158
- alwaysCalledWithExactly(spy: SinonSpy, ...args: any[]): void;
1149
+ alwaysCalledWithExactly<TArgs extends any[]>(spy: SinonSpy<TArgs>, ...args: MatchArguments<TArgs>): void;
1159
1150
  /**
1160
1151
  * Passes if spy was called with matching arguments.
1161
1152
  * This behaves the same way as sinon.assert.calledWith(spy, sinon.match(arg1), sinon.match(arg2), ...).
1162
- * Its possible to assert on a dedicated spy call: sinon.assert.calledWithMatch(spy.secondCall, arg1, arg2, ...);.
1153
+ * It's possible to assert on a dedicated spy call: sinon.assert.calledWithMatch(spy.secondCall, arg1, arg2, ...);.
1154
+ */
1155
+ calledWithMatch<TArgs extends any[]>(spyOrSpyCall: SinonSpy<TArgs> | SinonSpyCall<TArgs>, ...args: TArgs): void;
1156
+ /**
1157
+ * Passes if spy was called once with matching arguments.
1158
+ * This behaves the same way as calling both sinon.assert.calledOnce(spy) and
1159
+ * sinon.assert.calledWithMatch(spy, ...).
1163
1160
  */
1164
- calledWithMatch(spyOrSpyCall: SinonSpy | SinonSpyCall, ...args: any[]): void;
1161
+ calledOnceWithMatch<TArgs extends any[]>(
1162
+ spyOrSpyCall: SinonSpy<TArgs> | SinonSpyCall<TArgs>,
1163
+ ...args: TArgs
1164
+ ): void;
1165
1165
  /**
1166
1166
  * Passes if spy was always called with matching arguments.
1167
1167
  * This behaves the same way as sinon.assert.alwaysCalledWith(spy, sinon.match(arg1), sinon.match(arg2), ...).
1168
1168
  */
1169
- alwaysCalledWithMatch(spy: SinonSpy, ...args: any[]): void;
1169
+ alwaysCalledWithMatch<TArgs extends any[]>(spy: SinonSpy<TArgs>, ...args: TArgs): void;
1170
1170
  /**
1171
1171
  * Passes if spy was never called with matching arguments.
1172
1172
  * This behaves the same way as sinon.assert.neverCalledWith(spy, sinon.match(arg1), sinon.match(arg2), ...).
1173
1173
  * @param spy
1174
1174
  * @param args
1175
1175
  */
1176
- neverCalledWithMatch(spy: SinonSpy, ...args: any[]): void;
1176
+ neverCalledWithMatch<TArgs extends any[]>(spy: SinonSpy<TArgs>, ...args: TArgs): void;
1177
1177
  /**
1178
1178
  * Passes if spy was called with the new operator.
1179
1179
  * It’s possible to assert on a dedicated spy call: sinon.assert.calledWithNew(spy.secondCall, arg1, arg2, ...);.
1180
1180
  * @param spyOrSpyCall
1181
1181
  */
1182
- calledWithNew(spyOrSpyCall: SinonSpy | SinonSpyCall): void;
1182
+ calledWithNew(spyOrSpyCall: SinonSpy<any> | SinonSpyCall<any>): void;
1183
1183
  /**
1184
1184
  * Passes if spy threw any exception.
1185
1185
  */
1186
- threw(spyOrSpyCall: SinonSpy | SinonSpyCall): void;
1186
+ threw(spyOrSpyCall: SinonSpy<any> | SinonSpyCall<any>): void;
1187
1187
  /**
1188
1188
  * Passes if spy threw the given exception.
1189
1189
  * The exception is an actual object.
1190
1190
  * It’s possible to assert on a dedicated spy call: sinon.assert.threw(spy.thirdCall, exception);.
1191
1191
  */
1192
- threw(spyOrSpyCall: SinonSpy | SinonSpyCall, exception: string): void;
1192
+ threw(spyOrSpyCall: SinonSpy<any> | SinonSpyCall<any>, exception: string): void;
1193
1193
  /**
1194
1194
  * Passes if spy threw the given exception.
1195
1195
  * The exception is a String denoting its type.
1196
1196
  * It’s possible to assert on a dedicated spy call: sinon.assert.threw(spy.thirdCall, exception);.
1197
1197
  */
1198
- threw(spyOrSpyCall: SinonSpy | SinonSpyCall, exception: any): void;
1198
+ threw(spyOrSpyCall: SinonSpy<any> | SinonSpyCall<any>, exception: any): void;
1199
+
1199
1200
  /**
1200
1201
  * Like threw, only required for all calls to the spy.
1201
1202
  */
1202
- alwaysThrew(spy: SinonSpy): void;
1203
+ alwaysThrew(spy: SinonSpy<any>): void;
1203
1204
  /**
1204
1205
  * Like threw, only required for all calls to the spy.
1205
1206
  */
1206
- alwaysThrew(spy: SinonSpy, exception: string): void;
1207
+ alwaysThrew(spy: SinonSpy<any>, exception: string): void;
1207
1208
  /**
1208
1209
  * Like threw, only required for all calls to the spy.
1209
1210
  */
1210
- alwaysThrew(spy: SinonSpy, exception: any): void;
1211
+ alwaysThrew(spy: SinonSpy<any>, exception: any): void;
1212
+
1211
1213
  /**
1212
1214
  * Uses sinon.match to test if the arguments can be considered a match.
1213
1215
  */
@@ -1463,7 +1465,9 @@ declare namespace Sinon {
1463
1465
  /**
1464
1466
  * Replaces a type with a Sinon stub if it's a function.
1465
1467
  */
1466
- type SinonStubbedMember<T> = T extends Function ? SinonStub : T;
1468
+ type SinonStubbedMember<T> = T extends (...args: infer TArgs) => infer TReturnValue
1469
+ ? SinonStub<TArgs, TReturnValue>
1470
+ : T;
1467
1471
 
1468
1472
  interface SinonFake {
1469
1473
  /**
@@ -1517,6 +1521,7 @@ declare namespace Sinon {
1517
1521
  clock: SinonFakeTimers;
1518
1522
  requests: SinonFakeXMLHttpRequest[];
1519
1523
  server: SinonFakeServer;
1524
+ match: SinonMatch;
1520
1525
  /**
1521
1526
  * Works exactly like sinon.spy
1522
1527
  */
@@ -1530,6 +1535,8 @@ declare namespace Sinon {
1530
1535
  */
1531
1536
  mock: SinonMockStatic;
1532
1537
 
1538
+ fake: SinonFake;
1539
+
1533
1540
  /**
1534
1541
  * * No param : Causes Sinon to replace the global setTimeout, clearTimeout, setInterval, clearInterval, setImmediate, clearImmediate, process.hrtime, performance.now(when available)
1535
1542
  * and Date with a custom implementation which is bound to the returned clock object.
@@ -1598,10 +1605,7 @@ declare namespace Sinon {
1598
1605
  * replacement can be any value, including spies, stubs and fakes.
1599
1606
  * This method only works on non-accessor properties, for replacing accessors, use sandbox.replaceGetter() and sandbox.replaceSetter().
1600
1607
  */
1601
- replace<T, TKey extends keyof T>(
1602
- obj: T,
1603
- prop: TKey,
1604
- replacement: T[TKey]): T[TKey];
1608
+ replace<T, TKey extends keyof T>(obj: T, prop: TKey, replacement: T[TKey]): T[TKey];
1605
1609
  /**
1606
1610
  * Replaces getter for property on object with replacement argument. Attempts to replace an already replaced getter cause an exception.
1607
1611
  * replacement must be a Function, and can be instances of spies, stubs and fakes.
@@ -1609,10 +1613,7 @@ declare namespace Sinon {
1609
1613
  * @param prop
1610
1614
  * @param replacement
1611
1615
  */
1612
- replaceGetter<T, TKey extends keyof T>(
1613
- obj: T,
1614
- prop: TKey,
1615
- replacement: () => T[TKey]): () => T[TKey];
1616
+ replaceGetter<T, TKey extends keyof T>(obj: T, prop: TKey, replacement: () => T[TKey]): () => T[TKey];
1616
1617
  /**
1617
1618
  * Replaces setter for property on object with replacement argument. Attempts to replace an already replaced setter cause an exception.
1618
1619
  * replacement must be a Function, and can be instances of spies, stubs and fakes.
@@ -1623,7 +1624,8 @@ declare namespace Sinon {
1623
1624
  replaceSetter<T, TKey extends keyof T>(
1624
1625
  obj: T,
1625
1626
  prop: TKey,
1626
- replacement: (val: T[TKey]) => void): (val: T[TKey]) => void;
1627
+ replacement: (val: T[TKey]) => void,
1628
+ ): (val: T[TKey]) => void;
1627
1629
 
1628
1630
  /**
1629
1631
  * Creates a new object with the given functions as the prototype and stubs all implemented functions.
@@ -1636,14 +1638,15 @@ declare namespace Sinon {
1636
1638
  */
1637
1639
  createStubInstance<TType>(
1638
1640
  constructor: StubbableType<TType>,
1639
- overrides?: { [K in keyof TType]?: any }
1641
+ overrides?: {
1642
+ [K in keyof TType]?:
1643
+ | SinonStubbedMember<TType[K]>
1644
+ | (TType[K] extends (...args: any[]) => infer R ? R : TType[K]);
1645
+ },
1640
1646
  ): SinonStubbedInstance<TType>;
1641
1647
  }
1642
1648
 
1643
1649
  interface SinonApi {
1644
- fake: SinonFake;
1645
- match: SinonMatch;
1646
- spyCall(...args: any[]): SinonSpyCall;
1647
1650
  expectation: SinonExpectationStatic;
1648
1651
 
1649
1652
  clock: {
@@ -1661,18 +1664,25 @@ declare namespace Sinon {
1661
1664
  */
1662
1665
  createSandbox(config?: Partial<SinonSandboxConfig>): SinonSandbox;
1663
1666
  defaultConfig: Partial<SinonSandboxConfig>;
1664
- }
1665
1667
 
1666
- interface LegacySandbox {
1667
- sandbox: {
1668
- /**
1669
- * @deprecated Since 5.0, use `sinon.createSandbox` instead
1670
- */
1671
- create(config?: Partial<SinonSandboxConfig>): SinonSandbox;
1672
- };
1668
+ /**
1669
+ * Add a custom behavior.
1670
+ * The name will be available as a function on stubs, and the chaining mechanism
1671
+ * will be set up for you (e.g. no need to return anything from your function,
1672
+ * its return value will be ignored). The fn will be passed the fake instance
1673
+ * as its first argument, and then the user's arguments.
1674
+ */
1675
+ addBehavior: (name: string, fn: (fake: SinonStub, ...userArgs: any[]) => void) => void;
1676
+
1677
+ /**
1678
+ * Replace the default formatter used when formatting ECMAScript object
1679
+ * An example converts a basic object, such as {id: 42 }, to a string
1680
+ * on a format of your choosing, such as "{ id: 42 }"
1681
+ */
1682
+ setFormatter: (customFormatter: (...args: any[]) => string) => void;
1673
1683
  }
1674
1684
 
1675
- type SinonStatic = SinonSandbox & LegacySandbox & SinonApi;
1685
+ type SinonStatic = SinonSandbox & SinonApi;
1676
1686
  }
1677
1687
 
1678
1688
  declare const Sinon: Sinon.SinonStatic;