cypress 6.2.0 → 6.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cli.js +21 -1
- package/lib/exec/open.js +9 -1
- package/lib/exec/run.js +9 -1
- package/lib/exec/xvfb.js +4 -3
- package/lib/tasks/cache.js +6 -3
- package/lib/tasks/install.js +1 -1
- package/lib/util.js +1 -1
- package/package.json +5 -3
- package/types/chai/index.d.ts +13 -3
- package/types/cy-http.d.ts +13 -0
- package/types/cypress-global-vars.d.ts +0 -2
- package/types/cypress.d.ts +194 -35
- package/types/net-stubbing.ts +8 -3
- package/types/sinon/index.d.ts +204 -140
- package/types/sinon/ts3.1/index.d.ts +0 -1703
package/types/sinon/index.d.ts
CHANGED
@@ -9,25 +9,27 @@
|
|
9
9
|
// John Wood <https://github.com/johnjesse>
|
10
10
|
// Alec Flett <https://github.com/alecf>
|
11
11
|
// Simon Schick <https://github.com/SimonSchick>
|
12
|
-
// Roey Berman <https://github.com/bergundy>
|
13
12
|
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
14
|
-
// TypeScript Version: 2.8
|
15
13
|
|
16
14
|
import * as FakeTimers from '@sinonjs/fake-timers';
|
17
15
|
|
18
16
|
// sinon uses DOM dependencies which are absent in browser-less environment like node.js
|
19
17
|
// to avoid compiler errors this monkey patch is used
|
20
18
|
// see more details in https://github.com/DefinitelyTyped/DefinitelyTyped/issues/11351
|
21
|
-
interface Event {
|
22
|
-
interface Document {
|
19
|
+
interface Event {} // tslint:disable-line no-empty-interface
|
20
|
+
interface Document {} // tslint:disable-line no-empty-interface
|
23
21
|
|
24
22
|
declare namespace Sinon {
|
25
|
-
|
23
|
+
type MatchArguments<T> = {
|
24
|
+
[K in keyof T]: SinonMatcher | (T[K] extends object ? MatchArguments<T[K]> : never) | T[K];
|
25
|
+
};
|
26
|
+
|
27
|
+
interface SinonSpyCallApi<TArgs extends any[] = any[], TReturnValue = any> {
|
26
28
|
// Properties
|
27
29
|
/**
|
28
30
|
* Array of received arguments.
|
29
31
|
*/
|
30
|
-
args:
|
32
|
+
args: TArgs;
|
31
33
|
|
32
34
|
// Methods
|
33
35
|
/**
|
@@ -42,11 +44,11 @@ declare namespace Sinon {
|
|
42
44
|
* so a call that received the provided arguments (in the same spots) and possibly others as well will return true.
|
43
45
|
* @param args
|
44
46
|
*/
|
45
|
-
calledWith(...args:
|
47
|
+
calledWith(...args: Partial<MatchArguments<TArgs>>): boolean;
|
46
48
|
/**
|
47
49
|
* Returns true if spy was called at least once with the provided arguments and no others.
|
48
50
|
*/
|
49
|
-
calledWithExactly(...args:
|
51
|
+
calledWithExactly(...args: MatchArguments<TArgs>): boolean;
|
50
52
|
/**
|
51
53
|
* Returns true if spy/stub was called the new operator.
|
52
54
|
* Beware that this is inferred based on the value of the this object and the spy function’s prototype,
|
@@ -57,31 +59,31 @@ declare namespace Sinon {
|
|
57
59
|
* Returns true if spy was called at exactly once with the provided arguments.
|
58
60
|
* @param args
|
59
61
|
*/
|
60
|
-
calledOnceWith(...args:
|
61
|
-
calledOnceWithExactly(...args:
|
62
|
+
calledOnceWith(...args: MatchArguments<TArgs>): boolean;
|
63
|
+
calledOnceWithExactly(...args: MatchArguments<TArgs>): boolean;
|
62
64
|
/**
|
63
65
|
* Returns true if spy was called with matching arguments (and possibly others).
|
64
66
|
* This behaves the same as spy.calledWith(sinon.match(arg1), sinon.match(arg2), ...).
|
65
67
|
* @param args
|
66
68
|
*/
|
67
|
-
calledWithMatch(...args:
|
69
|
+
calledWithMatch(...args: TArgs): boolean;
|
68
70
|
/**
|
69
71
|
* Returns true if call did not receive provided arguments.
|
70
72
|
* @param args
|
71
73
|
*/
|
72
|
-
notCalledWith(...args:
|
74
|
+
notCalledWith(...args: MatchArguments<TArgs>): boolean;
|
73
75
|
/**
|
74
76
|
* Returns true if call did not receive matching arguments.
|
75
77
|
* This behaves the same as spyCall.notCalledWith(sinon.match(arg1), sinon.match(arg2), ...).
|
76
78
|
* @param args
|
77
79
|
*/
|
78
|
-
notCalledWithMatch(...args:
|
80
|
+
notCalledWithMatch(...args: TArgs): boolean;
|
79
81
|
/**
|
80
82
|
* Returns true if spy returned the provided value at least once.
|
81
83
|
* Uses deep comparison for objects and arrays. Use spy.returned(sinon.match.same(obj)) for strict comparison (see matchers).
|
82
84
|
* @param value
|
83
85
|
*/
|
84
|
-
returned(value:
|
86
|
+
returned(value: TReturnValue | SinonMatcher): boolean;
|
85
87
|
/**
|
86
88
|
* Returns true if spy threw an exception at least once.
|
87
89
|
*/
|
@@ -122,7 +124,8 @@ declare namespace Sinon {
|
|
122
124
|
yieldToOn(property: string, obj: any, ...args: any[]): void;
|
123
125
|
}
|
124
126
|
|
125
|
-
interface SinonSpyCall extends
|
127
|
+
interface SinonSpyCall<TArgs extends any[] = any[], TReturnValue = any>
|
128
|
+
extends SinonSpyCallApi<TArgs, TReturnValue> {
|
126
129
|
/**
|
127
130
|
* The call’s this value.
|
128
131
|
*/
|
@@ -134,12 +137,18 @@ declare namespace Sinon {
|
|
134
137
|
/**
|
135
138
|
* Return value.
|
136
139
|
*/
|
137
|
-
returnValue:
|
140
|
+
returnValue: TReturnValue;
|
138
141
|
/**
|
139
142
|
* This property is a convenience for a call’s callback.
|
140
143
|
* When the last argument in a call is a Function, then callback will reference that. Otherwise it will be undefined.
|
141
144
|
*/
|
142
145
|
callback: Function | undefined;
|
146
|
+
|
147
|
+
/**
|
148
|
+
* This property is a convenience for the first argument of the call.
|
149
|
+
*/
|
150
|
+
firstArg: any;
|
151
|
+
|
143
152
|
/**
|
144
153
|
* This property is a convenience for the last argument of the call.
|
145
154
|
*/
|
@@ -148,16 +157,21 @@ declare namespace Sinon {
|
|
148
157
|
/**
|
149
158
|
* Returns true if the spy call occurred before another spy call.
|
150
159
|
* @param call
|
160
|
+
*
|
151
161
|
*/
|
152
|
-
calledBefore(call: SinonSpyCall): boolean;
|
162
|
+
calledBefore(call: SinonSpyCall<any>): boolean;
|
153
163
|
/**
|
154
164
|
* Returns true if the spy call occurred after another spy call.
|
155
165
|
* @param call
|
156
166
|
*/
|
157
|
-
calledAfter(call: SinonSpyCall): boolean;
|
167
|
+
calledAfter(call: SinonSpyCall<any>): boolean;
|
158
168
|
}
|
159
169
|
|
160
|
-
interface SinonSpy extends
|
170
|
+
interface SinonSpy<TArgs extends any[] = any[], TReturnValue = any>
|
171
|
+
extends Pick<
|
172
|
+
SinonSpyCallApi<TArgs, TReturnValue>,
|
173
|
+
Exclude<keyof SinonSpyCallApi<TArgs, TReturnValue>, 'args'>
|
174
|
+
> {
|
161
175
|
// Properties
|
162
176
|
/**
|
163
177
|
* The number of recorded calls.
|
@@ -186,19 +200,19 @@ declare namespace Sinon {
|
|
186
200
|
/**
|
187
201
|
* The first call
|
188
202
|
*/
|
189
|
-
firstCall: SinonSpyCall
|
203
|
+
firstCall: SinonSpyCall<TArgs, TReturnValue>;
|
190
204
|
/**
|
191
205
|
* The second call
|
192
206
|
*/
|
193
|
-
secondCall: SinonSpyCall
|
207
|
+
secondCall: SinonSpyCall<TArgs, TReturnValue>;
|
194
208
|
/**
|
195
209
|
* The third call
|
196
210
|
*/
|
197
|
-
thirdCall: SinonSpyCall
|
211
|
+
thirdCall: SinonSpyCall<TArgs, TReturnValue>;
|
198
212
|
/**
|
199
213
|
* The last call
|
200
214
|
*/
|
201
|
-
lastCall: SinonSpyCall
|
215
|
+
lastCall: SinonSpyCall<TArgs, TReturnValue>;
|
202
216
|
/**
|
203
217
|
* Array of this objects, spy.thisValues[0] is the this object for the first call.
|
204
218
|
*/
|
@@ -206,7 +220,7 @@ declare namespace Sinon {
|
|
206
220
|
/**
|
207
221
|
* Array of arguments received, spy.args[0] is an array of arguments received in the first call.
|
208
222
|
*/
|
209
|
-
args:
|
223
|
+
args: TArgs[];
|
210
224
|
/**
|
211
225
|
* Array of exception objects thrown, spy.exceptions[0] is the exception thrown by the first call.
|
212
226
|
* If the call did not throw an error, the value at the call’s location in .exceptions will be undefined.
|
@@ -216,41 +230,43 @@ declare namespace Sinon {
|
|
216
230
|
* Array of return values, spy.returnValues[0] is the return value of the first call.
|
217
231
|
* If the call did not explicitly return a value, the value at the call’s location in .returnValues will be undefined.
|
218
232
|
*/
|
219
|
-
returnValues:
|
233
|
+
returnValues: TReturnValue[];
|
220
234
|
|
221
235
|
/**
|
222
236
|
* Holds a reference to the original method/function this stub has wrapped.
|
223
237
|
*/
|
224
|
-
wrappedMethod: (...args:
|
238
|
+
wrappedMethod: (...args: TArgs) => TReturnValue;
|
225
239
|
|
226
240
|
// Methods
|
227
|
-
(...args:
|
241
|
+
(...args: TArgs): TReturnValue;
|
242
|
+
|
228
243
|
/**
|
229
244
|
* Returns true if the spy was called before @param anotherSpy
|
230
245
|
* @param anotherSpy
|
231
246
|
*/
|
232
|
-
calledBefore(anotherSpy: SinonSpy): boolean;
|
247
|
+
calledBefore(anotherSpy: SinonSpy<any>): boolean;
|
233
248
|
/**
|
234
249
|
* Returns true if the spy was called after @param anotherSpy
|
235
250
|
* @param anotherSpy
|
236
251
|
*/
|
237
|
-
calledAfter(anotherSpy: SinonSpy): boolean;
|
252
|
+
calledAfter(anotherSpy: SinonSpy<any>): boolean;
|
238
253
|
/**
|
239
254
|
* Returns true if spy was called before @param anotherSpy, and no spy calls occurred between spy and @param anotherSpy.
|
240
255
|
* @param anotherSpy
|
241
256
|
*/
|
242
|
-
calledImmediatelyBefore(anotherSpy: SinonSpy): boolean;
|
257
|
+
calledImmediatelyBefore(anotherSpy: SinonSpy<any>): boolean;
|
243
258
|
/**
|
244
259
|
* Returns true if spy was called after @param anotherSpy, and no spy calls occurred between @param anotherSpy and spy.
|
245
260
|
* @param anotherSpy
|
246
261
|
*/
|
247
|
-
calledImmediatelyAfter(anotherSpy: SinonSpy): boolean;
|
262
|
+
calledImmediatelyAfter(anotherSpy: SinonSpy<any>): boolean;
|
263
|
+
|
248
264
|
/**
|
249
265
|
* Creates a spy that only records calls when the received arguments match those passed to withArgs.
|
250
266
|
* This is useful to be more expressive in your assertions, where you can access the spy with the same call.
|
251
267
|
* @param args Expected args
|
252
268
|
*/
|
253
|
-
withArgs(...args:
|
269
|
+
withArgs(...args: MatchArguments<TArgs>): SinonSpy<TArgs, TReturnValue>;
|
254
270
|
/**
|
255
271
|
* Returns true if the spy was always called with @param obj as this.
|
256
272
|
* @param obj
|
@@ -259,29 +275,29 @@ declare namespace Sinon {
|
|
259
275
|
/**
|
260
276
|
* Returns true if spy was always called with the provided arguments (and possibly others).
|
261
277
|
*/
|
262
|
-
alwaysCalledWith(...args:
|
278
|
+
alwaysCalledWith(...args: MatchArguments<TArgs>): boolean;
|
263
279
|
/**
|
264
280
|
* Returns true if spy was always called with the exact provided arguments.
|
265
281
|
* @param args
|
266
282
|
*/
|
267
|
-
alwaysCalledWithExactly(...args:
|
283
|
+
alwaysCalledWithExactly(...args: MatchArguments<TArgs>): boolean;
|
268
284
|
/**
|
269
285
|
* Returns true if spy was always called with matching arguments (and possibly others).
|
270
286
|
* This behaves the same as spy.alwaysCalledWith(sinon.match(arg1), sinon.match(arg2), ...).
|
271
287
|
* @param args
|
272
288
|
*/
|
273
|
-
alwaysCalledWithMatch(...args:
|
289
|
+
alwaysCalledWithMatch(...args: TArgs): boolean;
|
274
290
|
/**
|
275
291
|
* Returns true if the spy/stub was never called with the provided arguments.
|
276
292
|
* @param args
|
277
293
|
*/
|
278
|
-
neverCalledWith(...args:
|
294
|
+
neverCalledWith(...args: MatchArguments<TArgs>): boolean;
|
279
295
|
/**
|
280
296
|
* Returns true if the spy/stub was never called with matching arguments.
|
281
297
|
* This behaves the same as spy.neverCalledWith(sinon.match(arg1), sinon.match(arg2), ...).
|
282
298
|
* @param args
|
283
299
|
*/
|
284
|
-
neverCalledWithMatch(...args:
|
300
|
+
neverCalledWithMatch(...args: TArgs): boolean;
|
285
301
|
/**
|
286
302
|
* Returns true if spy always threw an exception.
|
287
303
|
*/
|
@@ -304,22 +320,22 @@ declare namespace Sinon {
|
|
304
320
|
* If the stub was never called with a function argument, yield throws an error.
|
305
321
|
* Returns an Array with all callbacks return values in the order they were called, if no error is thrown.
|
306
322
|
*/
|
307
|
-
invokeCallback(...args:
|
323
|
+
invokeCallback(...args: TArgs): void;
|
308
324
|
/**
|
309
325
|
* Set the displayName of the spy or stub.
|
310
326
|
* @param name
|
311
327
|
*/
|
312
|
-
named(name: string): SinonSpy
|
328
|
+
named(name: string): SinonSpy<TArgs, TReturnValue>;
|
313
329
|
/**
|
314
330
|
* Returns the nth call.
|
315
331
|
* Accessing individual calls helps with more detailed behavior verification when the spy is called more than once.
|
316
332
|
* @param n Zero based index of the spy call.
|
317
333
|
*/
|
318
|
-
getCall(n: number): SinonSpyCall
|
334
|
+
getCall(n: number): SinonSpyCall<TArgs, TReturnValue>;
|
319
335
|
/**
|
320
336
|
* Returns an Array of all calls recorded by the spy.
|
321
337
|
*/
|
322
|
-
getCalls(): SinonSpyCall
|
338
|
+
getCalls(): Array<SinonSpyCall<TArgs, TReturnValue>>;
|
323
339
|
/**
|
324
340
|
* Resets the state of a spy.
|
325
341
|
*/
|
@@ -351,7 +367,7 @@ declare namespace Sinon {
|
|
351
367
|
/**
|
352
368
|
* Spies on the provided function
|
353
369
|
*/
|
354
|
-
(func:
|
370
|
+
<F extends (...args: any[]) => any>(func: F): SinonSpy<Parameters<F>, ReturnType<F>>;
|
355
371
|
/**
|
356
372
|
* Creates a spy for object.method and replaces the original method with the spy.
|
357
373
|
* An exception is thrown if the property is not already a function.
|
@@ -359,10 +375,17 @@ declare namespace Sinon {
|
|
359
375
|
* The original method can be restored by calling object.method.restore().
|
360
376
|
* The returned spy is the function object which replaced the original method. spy === object.method.
|
361
377
|
*/
|
362
|
-
<T>(obj: T, method:
|
378
|
+
<T, K extends keyof T>(obj: T, method: K): T[K] extends (...args: infer TArgs) => infer TReturnValue
|
379
|
+
? SinonSpy<TArgs, TReturnValue>
|
380
|
+
: SinonSpy;
|
381
|
+
|
382
|
+
<T, K extends keyof T>(obj: T, method: K, types: Array<'get' | 'set'>): PropertyDescriptor & {
|
383
|
+
get: SinonSpy<[], T[K]>;
|
384
|
+
set: SinonSpy<[T[K]], void>;
|
385
|
+
};
|
363
386
|
}
|
364
387
|
|
365
|
-
interface SinonStub extends SinonSpy {
|
388
|
+
interface SinonStub<TArgs extends any[] = any[], TReturnValue = any> extends SinonSpy<TArgs, TReturnValue> {
|
366
389
|
/**
|
367
390
|
* Resets the stub’s behaviour to the default behaviour
|
368
391
|
* You can reset behaviour of all stubs using sinon.resetBehavior()
|
@@ -380,13 +403,13 @@ declare namespace Sinon {
|
|
380
403
|
* Causes the stub to return promises using a specific Promise library instead of the global one when using stub.rejects or stub.resolves.
|
381
404
|
* Returns the stub to allow chaining.
|
382
405
|
*/
|
383
|
-
usingPromise(promiseLibrary: any): SinonStub
|
406
|
+
usingPromise(promiseLibrary: any): SinonStub<TArgs, TReturnValue>;
|
384
407
|
|
385
408
|
/**
|
386
409
|
* Makes the stub return the provided @param obj value.
|
387
410
|
* @param obj
|
388
411
|
*/
|
389
|
-
returns(obj:
|
412
|
+
returns(obj: TReturnValue): SinonStub<TArgs, TReturnValue>;
|
390
413
|
/**
|
391
414
|
* Causes the stub to return the argument at the provided @param index.
|
392
415
|
* stub.returnsArg(0); causes the stub to return the first argument.
|
@@ -394,12 +417,12 @@ declare namespace Sinon {
|
|
394
417
|
* starting from sinon@6.1.2, a TypeError will be thrown.
|
395
418
|
* @param index
|
396
419
|
*/
|
397
|
-
returnsArg(index: number): SinonStub
|
420
|
+
returnsArg(index: number): SinonStub<TArgs, TReturnValue>;
|
398
421
|
/**
|
399
422
|
* Causes the stub to return its this value.
|
400
423
|
* Useful for stubbing jQuery-style fluent APIs.
|
401
424
|
*/
|
402
|
-
returnsThis(): SinonStub
|
425
|
+
returnsThis(): SinonStub<TArgs, TReturnValue>;
|
403
426
|
/**
|
404
427
|
* Causes the stub to return a Promise which resolves to the provided value.
|
405
428
|
* When constructing the Promise, sinon uses the Promise.resolve method.
|
@@ -407,26 +430,28 @@ declare namespace Sinon {
|
|
407
430
|
* The Promise library can be overwritten using the usingPromise method.
|
408
431
|
* Since sinon@2.0.0
|
409
432
|
*/
|
410
|
-
resolves(
|
433
|
+
resolves(
|
434
|
+
value?: TReturnValue extends PromiseLike<infer TResolveValue> ? TResolveValue : any,
|
435
|
+
): SinonStub<TArgs, TReturnValue>;
|
411
436
|
/**
|
412
437
|
* Causes the stub to return a Promise which resolves to the argument at the provided index.
|
413
438
|
* stub.resolvesArg(0); causes the stub to return a Promise which resolves to the first argument.
|
414
439
|
* If the argument at the provided index is not available, a TypeError will be thrown.
|
415
440
|
*/
|
416
|
-
resolvesArg(index: number): SinonStub
|
441
|
+
resolvesArg(index: number): SinonStub<TArgs, TReturnValue>;
|
417
442
|
/**
|
418
443
|
* Causes the stub to return a Promise which resolves to its this value.
|
419
444
|
*/
|
420
|
-
resolvesThis(): SinonStub
|
445
|
+
resolvesThis(): SinonStub<TArgs, TReturnValue>;
|
421
446
|
/**
|
422
447
|
* Causes the stub to throw an exception (Error).
|
423
448
|
* @param type
|
424
449
|
*/
|
425
|
-
throws(type?: string): SinonStub
|
450
|
+
throws(type?: string): SinonStub<TArgs, TReturnValue>;
|
426
451
|
/**
|
427
452
|
* Causes the stub to throw the provided exception object.
|
428
453
|
*/
|
429
|
-
throws(obj: any): SinonStub
|
454
|
+
throws(obj: any): SinonStub<TArgs, TReturnValue>;
|
430
455
|
/**
|
431
456
|
* Causes the stub to throw the argument at the provided index.
|
432
457
|
* stub.throwsArg(0); causes the stub to throw the first argument as the exception.
|
@@ -434,9 +459,9 @@ declare namespace Sinon {
|
|
434
459
|
* Since sinon@2.3.0
|
435
460
|
* @param index
|
436
461
|
*/
|
437
|
-
throwsArg(index: number): SinonStub
|
438
|
-
throwsException(type?: string): SinonStub
|
439
|
-
throwsException(obj: any): SinonStub
|
462
|
+
throwsArg(index: number): SinonStub<TArgs, TReturnValue>;
|
463
|
+
throwsException(type?: string): SinonStub<TArgs, TReturnValue>;
|
464
|
+
throwsException(obj: any): SinonStub<TArgs, TReturnValue>;
|
440
465
|
/**
|
441
466
|
* Causes the stub to return a Promise which rejects with an exception (Error).
|
442
467
|
* When constructing the Promise, sinon uses the Promise.reject method.
|
@@ -444,53 +469,53 @@ declare namespace Sinon {
|
|
444
469
|
* The Promise library can be overwritten using the usingPromise method.
|
445
470
|
* Since sinon@2.0.0
|
446
471
|
*/
|
447
|
-
rejects(): SinonStub
|
472
|
+
rejects(): SinonStub<TArgs, TReturnValue>;
|
448
473
|
/**
|
449
474
|
* Causes the stub to return a Promise which rejects with an exception of the provided type.
|
450
475
|
* Since sinon@2.0.0
|
451
476
|
*/
|
452
|
-
rejects(errorType: string): SinonStub
|
477
|
+
rejects(errorType: string): SinonStub<TArgs, TReturnValue>;
|
453
478
|
/**
|
454
479
|
* Causes the stub to return a Promise which rejects with the provided exception object.
|
455
480
|
* Since sinon@2.0.0
|
456
481
|
*/
|
457
|
-
rejects(value: any): SinonStub
|
482
|
+
rejects(value: any): SinonStub<TArgs, TReturnValue>;
|
458
483
|
/**
|
459
484
|
* Causes the stub to call the argument at the provided index as a callback function.
|
460
485
|
* stub.callsArg(0); causes the stub to call the first argument as a callback.
|
461
486
|
* If the argument at the provided index is not available or is not a function, a TypeError will be thrown.
|
462
487
|
*/
|
463
|
-
callsArg(index: number): SinonStub
|
488
|
+
callsArg(index: number): SinonStub<TArgs, TReturnValue>;
|
464
489
|
/**
|
465
490
|
* Causes the original method wrapped into the stub to be called when none of the conditional stubs are matched.
|
466
491
|
*/
|
467
|
-
callThrough(): SinonStub
|
492
|
+
callThrough(): SinonStub<TArgs, TReturnValue>;
|
468
493
|
/**
|
469
494
|
* Like stub.callsArg(index); but with an additional parameter to pass the this context.
|
470
495
|
* @param index
|
471
496
|
* @param context
|
472
497
|
*/
|
473
|
-
callsArgOn(index: number, context: any): SinonStub
|
498
|
+
callsArgOn(index: number, context: any): SinonStub<TArgs, TReturnValue>;
|
474
499
|
/**
|
475
500
|
* Like callsArg, but with arguments to pass to the callback.
|
476
501
|
* @param index
|
477
502
|
* @param args
|
478
503
|
*/
|
479
|
-
callsArgWith(index: number, ...args: any[]): SinonStub
|
504
|
+
callsArgWith(index: number, ...args: any[]): SinonStub<TArgs, TReturnValue>;
|
480
505
|
/**
|
481
506
|
* Like above but with an additional parameter to pass the this context.
|
482
507
|
* @param index
|
483
508
|
* @param context
|
484
509
|
* @param args
|
485
510
|
*/
|
486
|
-
callsArgOnWith(index: number, context: any, ...args: any[]): SinonStub
|
511
|
+
callsArgOnWith(index: number, context: any, ...args: any[]): SinonStub<TArgs, TReturnValue>;
|
487
512
|
/**
|
488
513
|
* Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
|
489
514
|
* In Node environment the callback is deferred with process.nextTick.
|
490
515
|
* In a browser the callback is deferred with setTimeout(callback, 0).
|
491
516
|
* @param index
|
492
517
|
*/
|
493
|
-
callsArgAsync(index: number): SinonStub
|
518
|
+
callsArgAsync(index: number): SinonStub<TArgs, TReturnValue>;
|
494
519
|
/**
|
495
520
|
* Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
|
496
521
|
* In Node environment the callback is deferred with process.nextTick.
|
@@ -498,91 +523,91 @@ declare namespace Sinon {
|
|
498
523
|
* @param index
|
499
524
|
* @param context
|
500
525
|
*/
|
501
|
-
callsArgOnAsync(index: number, context: any): SinonStub
|
526
|
+
callsArgOnAsync(index: number, context: any): SinonStub<TArgs, TReturnValue>;
|
502
527
|
/**
|
503
528
|
* 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
529
|
* In Node environment the callback is deferred with process.nextTick.
|
505
530
|
* In a browser the callback is deferred with setTimeout(callback, 0).
|
506
531
|
*/
|
507
|
-
callsArgWithAsync(index: number, ...args: any[]): SinonStub
|
532
|
+
callsArgWithAsync(index: number, ...args: any[]): SinonStub<TArgs, TReturnValue>;
|
508
533
|
/**
|
509
534
|
* Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
|
510
535
|
* In Node environment the callback is deferred with process.nextTick.
|
511
536
|
* In a browser the callback is deferred with setTimeout(callback, 0).
|
512
537
|
*/
|
513
|
-
callsArgOnWithAsync(index: number, context: any, ...args: any[]): SinonStub
|
538
|
+
callsArgOnWithAsync(index: number, context: any, ...args: any[]): SinonStub<TArgs, TReturnValue>;
|
514
539
|
/**
|
515
540
|
* Makes the stub call the provided @param func when invoked.
|
516
541
|
* @param func
|
517
542
|
*/
|
518
|
-
callsFake(func: (...args:
|
543
|
+
callsFake(func: (...args: TArgs) => TReturnValue): SinonStub<TArgs, TReturnValue>;
|
519
544
|
/**
|
520
545
|
* Replaces a new getter for this stub.
|
521
546
|
*/
|
522
|
-
get(func: () => any): SinonStub
|
547
|
+
get(func: () => any): SinonStub<TArgs, TReturnValue>;
|
523
548
|
/**
|
524
549
|
* Defines a new setter for this stub.
|
525
550
|
* @param func
|
526
551
|
*/
|
527
|
-
set(func: (v: any) => void): SinonStub
|
552
|
+
set(func: (v: any) => void): SinonStub<TArgs, TReturnValue>;
|
528
553
|
/**
|
529
554
|
* Defines the behavior of the stub on the @param n call. Useful for testing sequential interactions.
|
530
555
|
* There are methods onFirstCall, onSecondCall,onThirdCall to make stub definitions read more naturally.
|
531
556
|
* onCall can be combined with all of the behavior defining methods in this section. In particular, it can be used together with withArgs.
|
532
557
|
* @param n
|
533
558
|
*/
|
534
|
-
onCall(n: number): SinonStub
|
559
|
+
onCall(n: number): SinonStub<TArgs, TReturnValue>;
|
535
560
|
/**
|
536
561
|
* Alias for stub.onCall(0);
|
537
562
|
*/
|
538
|
-
onFirstCall(): SinonStub
|
563
|
+
onFirstCall(): SinonStub<TArgs, TReturnValue>;
|
539
564
|
/**
|
540
565
|
* Alias for stub.onCall(1);
|
541
566
|
*/
|
542
|
-
onSecondCall(): SinonStub
|
567
|
+
onSecondCall(): SinonStub<TArgs, TReturnValue>;
|
543
568
|
/**
|
544
569
|
* Alias for stub.onCall(2);
|
545
570
|
*/
|
546
|
-
onThirdCall(): SinonStub
|
571
|
+
onThirdCall(): SinonStub<TArgs, TReturnValue>;
|
547
572
|
/**
|
548
573
|
* Defines a new value for this stub.
|
549
574
|
* @param val
|
550
575
|
*/
|
551
|
-
value(val: any): SinonStub
|
576
|
+
value(val: any): SinonStub<TArgs, TReturnValue>;
|
552
577
|
/**
|
553
578
|
* Set the displayName of the spy or stub.
|
554
579
|
* @param name
|
555
580
|
*/
|
556
|
-
named(name: string): SinonStub
|
581
|
+
named(name: string): SinonStub<TArgs, TReturnValue>;
|
557
582
|
/**
|
558
583
|
* Similar to callsArg.
|
559
584
|
* Causes the stub to call the first callback it receives with the provided arguments (if any).
|
560
585
|
* If a method accepts more than one callback, you need to use callsArg to have the stub invoke other callbacks than the first one.
|
561
586
|
*/
|
562
|
-
yields(...args: any[]): SinonStub
|
587
|
+
yields(...args: any[]): SinonStub<TArgs, TReturnValue>;
|
563
588
|
/**
|
564
589
|
* Like above but with an additional parameter to pass the this context.
|
565
590
|
*/
|
566
|
-
yieldsOn(context: any, ...args: any[]): SinonStub
|
567
|
-
yieldsRight(...args: any[]): SinonStub
|
591
|
+
yieldsOn(context: any, ...args: any[]): SinonStub<TArgs, TReturnValue>;
|
592
|
+
yieldsRight(...args: any[]): SinonStub<TArgs, TReturnValue>;
|
568
593
|
/**
|
569
594
|
* Causes the spy to invoke a callback passed as a property of an object to the spy.
|
570
595
|
* Like yields, yieldsTo grabs the first matching argument, finds the callback and calls it with the (optional) arguments.
|
571
596
|
* @param property
|
572
597
|
* @param args
|
573
598
|
*/
|
574
|
-
yieldsTo(property: string, ...args: any[]): SinonStub
|
599
|
+
yieldsTo(property: string, ...args: any[]): SinonStub<TArgs, TReturnValue>;
|
575
600
|
/**
|
576
601
|
* Like above but with an additional parameter to pass the this context.
|
577
602
|
*/
|
578
|
-
yieldsToOn(property: string, context: any, ...args: any[]): SinonStub
|
603
|
+
yieldsToOn(property: string, context: any, ...args: any[]): SinonStub<TArgs, TReturnValue>;
|
579
604
|
/**
|
580
605
|
* Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
|
581
606
|
* In Node environment the callback is deferred with process.nextTick.
|
582
607
|
* In a browser the callback is deferred with setTimeout(callback, 0).
|
583
608
|
* @param args
|
584
609
|
*/
|
585
|
-
yieldsAsync(...args: any[]): SinonStub
|
610
|
+
yieldsAsync(...args: any[]): SinonStub<TArgs, TReturnValue>;
|
586
611
|
/**
|
587
612
|
* Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
|
588
613
|
* In Node environment the callback is deferred with process.nextTick.
|
@@ -590,7 +615,7 @@ declare namespace Sinon {
|
|
590
615
|
* @param context
|
591
616
|
* @param args
|
592
617
|
*/
|
593
|
-
yieldsOnAsync(context: any, ...args: any[]): SinonStub
|
618
|
+
yieldsOnAsync(context: any, ...args: any[]): SinonStub<TArgs, TReturnValue>;
|
594
619
|
/**
|
595
620
|
* Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
|
596
621
|
* In Node environment the callback is deferred with process.nextTick.
|
@@ -598,7 +623,7 @@ declare namespace Sinon {
|
|
598
623
|
* @param property
|
599
624
|
* @param args
|
600
625
|
*/
|
601
|
-
yieldsToAsync(property: string, ...args: any[]): SinonStub
|
626
|
+
yieldsToAsync(property: string, ...args: any[]): SinonStub<TArgs, TReturnValue>;
|
602
627
|
/**
|
603
628
|
* Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
|
604
629
|
* In Node environment the callback is deferred with process.nextTick.
|
@@ -607,21 +632,26 @@ declare namespace Sinon {
|
|
607
632
|
* @param context
|
608
633
|
* @param args
|
609
634
|
*/
|
610
|
-
yieldsToOnAsync(property: string, context: any, ...args: any[]): SinonStub
|
635
|
+
yieldsToOnAsync(property: string, context: any, ...args: any[]): SinonStub<TArgs, TReturnValue>;
|
611
636
|
/**
|
612
637
|
* Stubs the method only for the provided arguments.
|
613
638
|
* This is useful to be more expressive in your assertions, where you can access the spy with the same call.
|
614
639
|
* It is also useful to create a stub that can act differently in response to different arguments.
|
615
640
|
* @param args
|
616
641
|
*/
|
617
|
-
withArgs(...args:
|
642
|
+
withArgs(...args: MatchArguments<TArgs>): SinonStub<TArgs, TReturnValue>;
|
618
643
|
}
|
619
644
|
|
620
645
|
interface SinonStubStatic {
|
646
|
+
/* tslint:disable:no-unnecessary-generics */
|
647
|
+
|
621
648
|
/**
|
622
649
|
* Creates an anonymous stub function
|
623
650
|
*/
|
624
|
-
(): SinonStub
|
651
|
+
<TArgs extends any[] = any[], R = any>(): SinonStub<TArgs, R>;
|
652
|
+
|
653
|
+
/* tslint:enable:no-unnecessary-generics */
|
654
|
+
|
625
655
|
/**
|
626
656
|
* Stubs all the object’s methods.
|
627
657
|
* 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).
|
@@ -634,7 +664,9 @@ declare namespace Sinon {
|
|
634
664
|
* An exception is thrown if the property is not already a function.
|
635
665
|
* The original function can be restored by calling object.method.restore(); (or stub.restore();).
|
636
666
|
*/
|
637
|
-
<T>(obj: T, method:
|
667
|
+
<T, K extends keyof T>(obj: T, method: K): T[K] extends (...args: infer TArgs) => infer TReturnValue
|
668
|
+
? SinonStub<TArgs, TReturnValue>
|
669
|
+
: SinonStub;
|
638
670
|
}
|
639
671
|
|
640
672
|
interface SinonExpectation extends SinonStub {
|
@@ -841,7 +873,7 @@ declare namespace Sinon {
|
|
841
873
|
}
|
842
874
|
|
843
875
|
interface SinonFakeXMLHttpRequestStatic {
|
844
|
-
new(): SinonFakeXMLHttpRequest;
|
876
|
+
new (): SinonFakeXMLHttpRequest;
|
845
877
|
/**
|
846
878
|
* Default false.
|
847
879
|
* When set to true, Sinon will check added filters if certain requests should be “unfaked”
|
@@ -853,7 +885,9 @@ declare namespace Sinon {
|
|
853
885
|
* If the filter returns true, the request will not be faked.
|
854
886
|
* @param filter
|
855
887
|
*/
|
856
|
-
addFilter(
|
888
|
+
addFilter(
|
889
|
+
filter: (method: string, url: string, async: boolean, username: string, password: string) => boolean,
|
890
|
+
): void;
|
857
891
|
/**
|
858
892
|
* By assigning a function to the onCreate property of the returned object from useFakeXMLHttpRequest()
|
859
893
|
* you can subscribe to newly created FakeXMLHttpRequest objects. See below for the fake xhr object API.
|
@@ -1026,133 +1060,155 @@ declare namespace Sinon {
|
|
1026
1060
|
pass(assertion: any): void; // Overridable
|
1027
1061
|
|
1028
1062
|
// Methods
|
1063
|
+
|
1029
1064
|
/**
|
1030
1065
|
* Passes if spy was never called
|
1031
1066
|
* @param spy
|
1032
1067
|
*/
|
1033
|
-
notCalled(spy: SinonSpy): void;
|
1068
|
+
notCalled(spy: SinonSpy<any>): void;
|
1034
1069
|
/**
|
1035
1070
|
* Passes if spy was called at least once.
|
1036
1071
|
*/
|
1037
|
-
called(spy: SinonSpy): void;
|
1072
|
+
called(spy: SinonSpy<any>): void;
|
1038
1073
|
/**
|
1039
1074
|
* Passes if spy was called once and only once.
|
1040
1075
|
*/
|
1041
|
-
calledOnce(spy: SinonSpy): void;
|
1076
|
+
calledOnce(spy: SinonSpy<any>): void;
|
1042
1077
|
/**
|
1043
1078
|
* Passes if spy was called exactly twice.
|
1044
1079
|
*/
|
1045
|
-
calledTwice(spy: SinonSpy): void;
|
1080
|
+
calledTwice(spy: SinonSpy<any>): void;
|
1046
1081
|
/**
|
1047
1082
|
* Passes if spy was called exactly three times.
|
1048
1083
|
*/
|
1049
|
-
calledThrice(spy: SinonSpy): void;
|
1084
|
+
calledThrice(spy: SinonSpy<any>): void;
|
1050
1085
|
/**
|
1051
1086
|
* Passes if spy was called exactly num times.
|
1052
1087
|
*/
|
1053
|
-
callCount(spy: SinonSpy
|
1088
|
+
callCount(spy: SinonSpy<any>, count: number): void;
|
1054
1089
|
/**
|
1055
1090
|
* Passes if provided spies were called in the specified order.
|
1056
1091
|
* @param spies
|
1057
1092
|
*/
|
1058
|
-
callOrder(...spies: SinonSpy
|
1093
|
+
callOrder(...spies: Array<SinonSpy<any>>): void;
|
1059
1094
|
/**
|
1060
1095
|
* Passes if spy was ever called with obj as its this value.
|
1061
1096
|
* It’s possible to assert on a dedicated spy call: sinon.assert.calledOn(spy.firstCall, arg1, arg2, ...);.
|
1062
1097
|
*/
|
1063
|
-
calledOn(spyOrSpyCall: SinonSpy | SinonSpyCall
|
1098
|
+
calledOn(spyOrSpyCall: SinonSpy<any> | SinonSpyCall<any>, obj: any): void;
|
1064
1099
|
/**
|
1065
1100
|
* Passes if spy was always called with obj as its this value.
|
1066
1101
|
*/
|
1067
|
-
alwaysCalledOn(spy: SinonSpy
|
1102
|
+
alwaysCalledOn(spy: SinonSpy<any>, obj: any): void;
|
1103
|
+
|
1068
1104
|
/**
|
1069
1105
|
* Passes if spy was called with the provided arguments.
|
1070
1106
|
* It’s possible to assert on a dedicated spy call: sinon.assert.calledWith(spy.firstCall, arg1, arg2, ...);.
|
1071
1107
|
* @param spyOrSpyCall
|
1072
1108
|
* @param args
|
1073
1109
|
*/
|
1074
|
-
calledWith
|
1110
|
+
calledWith<TArgs extends any[]>(
|
1111
|
+
spyOrSpyCall: SinonSpy<TArgs> | SinonSpyCall<TArgs>,
|
1112
|
+
...args: MatchArguments<TArgs>
|
1113
|
+
): void;
|
1075
1114
|
/**
|
1076
1115
|
* Passes if spy was always called with the provided arguments.
|
1077
1116
|
* @param spy
|
1078
1117
|
* @param args
|
1079
1118
|
*/
|
1080
|
-
alwaysCalledWith(spy: SinonSpy
|
1119
|
+
alwaysCalledWith<TArgs extends any[]>(spy: SinonSpy<TArgs>, ...args: MatchArguments<TArgs>): void;
|
1081
1120
|
/**
|
1082
1121
|
* Passes if spy was never called with the provided arguments.
|
1083
1122
|
* @param spy
|
1084
1123
|
* @param args
|
1085
1124
|
*/
|
1086
|
-
neverCalledWith(spy: SinonSpy
|
1125
|
+
neverCalledWith<TArgs extends any[]>(spy: SinonSpy<TArgs>, ...args: MatchArguments<TArgs>): void;
|
1087
1126
|
/**
|
1088
1127
|
* Passes if spy was called with the provided arguments and no others.
|
1089
1128
|
* It’s possible to assert on a dedicated spy call: sinon.assert.calledWithExactly(spy.getCall(1), arg1, arg2, ...);.
|
1090
1129
|
* @param spyOrSpyCall
|
1091
1130
|
* @param args
|
1092
1131
|
*/
|
1093
|
-
calledWithExactly
|
1132
|
+
calledWithExactly<TArgs extends any[]>(
|
1133
|
+
spyOrSpyCall: SinonSpy<TArgs> | SinonSpyCall<TArgs>,
|
1134
|
+
...args: MatchArguments<TArgs>
|
1135
|
+
): void;
|
1094
1136
|
/**
|
1095
1137
|
* Passes if spy was called at exactly once with the provided arguments and no others.
|
1096
1138
|
* @param spyOrSpyCall
|
1097
1139
|
* @param args
|
1098
1140
|
*/
|
1099
|
-
calledOnceWithExactly
|
1141
|
+
calledOnceWithExactly<TArgs extends any[]>(
|
1142
|
+
spyOrSpyCall: SinonSpy<TArgs> | SinonSpyCall<TArgs>,
|
1143
|
+
...args: MatchArguments<TArgs>
|
1144
|
+
): void;
|
1100
1145
|
/**
|
1101
1146
|
* Passes if spy was always called with the provided arguments and no others.
|
1102
1147
|
*/
|
1103
|
-
alwaysCalledWithExactly(spy: SinonSpy
|
1148
|
+
alwaysCalledWithExactly<TArgs extends any[]>(spy: SinonSpy<TArgs>, ...args: MatchArguments<TArgs>): void;
|
1104
1149
|
/**
|
1105
1150
|
* Passes if spy was called with matching arguments.
|
1106
1151
|
* This behaves the same way as sinon.assert.calledWith(spy, sinon.match(arg1), sinon.match(arg2), ...).
|
1107
|
-
* It
|
1152
|
+
* It's possible to assert on a dedicated spy call: sinon.assert.calledWithMatch(spy.secondCall, arg1, arg2, ...);.
|
1153
|
+
*/
|
1154
|
+
calledWithMatch<TArgs extends any[]>(spyOrSpyCall: SinonSpy<TArgs> | SinonSpyCall<TArgs>, ...args: TArgs): void;
|
1155
|
+
/**
|
1156
|
+
* Passes if spy was called once with matching arguments.
|
1157
|
+
* This behaves the same way as calling both sinon.assert.calledOnce(spy) and
|
1158
|
+
* sinon.assert.calledWithMatch(spy, ...).
|
1108
1159
|
*/
|
1109
|
-
|
1160
|
+
calledOnceWithMatch<TArgs extends any[]>(
|
1161
|
+
spyOrSpyCall: SinonSpy<TArgs> | SinonSpyCall<TArgs>,
|
1162
|
+
...args: TArgs
|
1163
|
+
): void;
|
1110
1164
|
/**
|
1111
1165
|
* Passes if spy was always called with matching arguments.
|
1112
1166
|
* This behaves the same way as sinon.assert.alwaysCalledWith(spy, sinon.match(arg1), sinon.match(arg2), ...).
|
1113
1167
|
*/
|
1114
|
-
alwaysCalledWithMatch(spy: SinonSpy
|
1168
|
+
alwaysCalledWithMatch<TArgs extends any[]>(spy: SinonSpy<TArgs>, ...args: TArgs): void;
|
1115
1169
|
/**
|
1116
1170
|
* Passes if spy was never called with matching arguments.
|
1117
1171
|
* This behaves the same way as sinon.assert.neverCalledWith(spy, sinon.match(arg1), sinon.match(arg2), ...).
|
1118
1172
|
* @param spy
|
1119
1173
|
* @param args
|
1120
1174
|
*/
|
1121
|
-
neverCalledWithMatch(spy: SinonSpy
|
1175
|
+
neverCalledWithMatch<TArgs extends any[]>(spy: SinonSpy<TArgs>, ...args: TArgs): void;
|
1122
1176
|
/**
|
1123
1177
|
* Passes if spy was called with the new operator.
|
1124
1178
|
* It’s possible to assert on a dedicated spy call: sinon.assert.calledWithNew(spy.secondCall, arg1, arg2, ...);.
|
1125
1179
|
* @param spyOrSpyCall
|
1126
1180
|
*/
|
1127
|
-
calledWithNew(spyOrSpyCall: SinonSpy | SinonSpyCall): void;
|
1181
|
+
calledWithNew(spyOrSpyCall: SinonSpy<any> | SinonSpyCall<any>): void;
|
1128
1182
|
/**
|
1129
1183
|
* Passes if spy threw any exception.
|
1130
1184
|
*/
|
1131
|
-
threw(spyOrSpyCall: SinonSpy | SinonSpyCall): void;
|
1185
|
+
threw(spyOrSpyCall: SinonSpy<any> | SinonSpyCall<any>): void;
|
1132
1186
|
/**
|
1133
1187
|
* Passes if spy threw the given exception.
|
1134
1188
|
* The exception is an actual object.
|
1135
1189
|
* It’s possible to assert on a dedicated spy call: sinon.assert.threw(spy.thirdCall, exception);.
|
1136
1190
|
*/
|
1137
|
-
threw(spyOrSpyCall: SinonSpy | SinonSpyCall
|
1191
|
+
threw(spyOrSpyCall: SinonSpy<any> | SinonSpyCall<any>, exception: string): void;
|
1138
1192
|
/**
|
1139
1193
|
* Passes if spy threw the given exception.
|
1140
1194
|
* The exception is a String denoting its type.
|
1141
1195
|
* It’s possible to assert on a dedicated spy call: sinon.assert.threw(spy.thirdCall, exception);.
|
1142
1196
|
*/
|
1143
|
-
threw(spyOrSpyCall: SinonSpy | SinonSpyCall
|
1197
|
+
threw(spyOrSpyCall: SinonSpy<any> | SinonSpyCall<any>, exception: any): void;
|
1198
|
+
|
1144
1199
|
/**
|
1145
1200
|
* Like threw, only required for all calls to the spy.
|
1146
1201
|
*/
|
1147
|
-
alwaysThrew(spy: SinonSpy): void;
|
1202
|
+
alwaysThrew(spy: SinonSpy<any>): void;
|
1148
1203
|
/**
|
1149
1204
|
* Like threw, only required for all calls to the spy.
|
1150
1205
|
*/
|
1151
|
-
alwaysThrew(spy: SinonSpy
|
1206
|
+
alwaysThrew(spy: SinonSpy<any>, exception: string): void;
|
1152
1207
|
/**
|
1153
1208
|
* Like threw, only required for all calls to the spy.
|
1154
1209
|
*/
|
1155
|
-
alwaysThrew(spy: SinonSpy
|
1210
|
+
alwaysThrew(spy: SinonSpy<any>, exception: any): void;
|
1211
|
+
|
1156
1212
|
/**
|
1157
1213
|
* Uses sinon.match to test if the arguments can be considered a match.
|
1158
1214
|
*/
|
@@ -1408,7 +1464,9 @@ declare namespace Sinon {
|
|
1408
1464
|
/**
|
1409
1465
|
* Replaces a type with a Sinon stub if it's a function.
|
1410
1466
|
*/
|
1411
|
-
type SinonStubbedMember<T> = T extends
|
1467
|
+
type SinonStubbedMember<T> = T extends (...args: infer TArgs) => infer TReturnValue
|
1468
|
+
? SinonStub<TArgs, TReturnValue>
|
1469
|
+
: T;
|
1412
1470
|
|
1413
1471
|
interface SinonFake {
|
1414
1472
|
/**
|
@@ -1462,6 +1520,7 @@ declare namespace Sinon {
|
|
1462
1520
|
clock: SinonFakeTimers;
|
1463
1521
|
requests: SinonFakeXMLHttpRequest[];
|
1464
1522
|
server: SinonFakeServer;
|
1523
|
+
match: SinonMatch;
|
1465
1524
|
/**
|
1466
1525
|
* Works exactly like sinon.spy
|
1467
1526
|
*/
|
@@ -1475,6 +1534,8 @@ declare namespace Sinon {
|
|
1475
1534
|
*/
|
1476
1535
|
mock: SinonMockStatic;
|
1477
1536
|
|
1537
|
+
fake: SinonFake;
|
1538
|
+
|
1478
1539
|
/**
|
1479
1540
|
* * No param : Causes Sinon to replace the global setTimeout, clearTimeout, setInterval, clearInterval, setImmediate, clearImmediate, process.hrtime, performance.now(when available)
|
1480
1541
|
* and Date with a custom implementation which is bound to the returned clock object.
|
@@ -1543,10 +1604,7 @@ declare namespace Sinon {
|
|
1543
1604
|
* replacement can be any value, including spies, stubs and fakes.
|
1544
1605
|
* This method only works on non-accessor properties, for replacing accessors, use sandbox.replaceGetter() and sandbox.replaceSetter().
|
1545
1606
|
*/
|
1546
|
-
replace<T, TKey extends keyof T>(
|
1547
|
-
obj: T,
|
1548
|
-
prop: TKey,
|
1549
|
-
replacement: T[TKey]): T[TKey];
|
1607
|
+
replace<T, TKey extends keyof T>(obj: T, prop: TKey, replacement: T[TKey]): T[TKey];
|
1550
1608
|
/**
|
1551
1609
|
* Replaces getter for property on object with replacement argument. Attempts to replace an already replaced getter cause an exception.
|
1552
1610
|
* replacement must be a Function, and can be instances of spies, stubs and fakes.
|
@@ -1554,10 +1612,7 @@ declare namespace Sinon {
|
|
1554
1612
|
* @param prop
|
1555
1613
|
* @param replacement
|
1556
1614
|
*/
|
1557
|
-
replaceGetter<T, TKey extends keyof T>(
|
1558
|
-
obj: T,
|
1559
|
-
prop: TKey,
|
1560
|
-
replacement: () => T[TKey]): () => T[TKey];
|
1615
|
+
replaceGetter<T, TKey extends keyof T>(obj: T, prop: TKey, replacement: () => T[TKey]): () => T[TKey];
|
1561
1616
|
/**
|
1562
1617
|
* Replaces setter for property on object with replacement argument. Attempts to replace an already replaced setter cause an exception.
|
1563
1618
|
* replacement must be a Function, and can be instances of spies, stubs and fakes.
|
@@ -1568,7 +1623,8 @@ declare namespace Sinon {
|
|
1568
1623
|
replaceSetter<T, TKey extends keyof T>(
|
1569
1624
|
obj: T,
|
1570
1625
|
prop: TKey,
|
1571
|
-
replacement: (val: T[TKey]) => void
|
1626
|
+
replacement: (val: T[TKey]) => void,
|
1627
|
+
): (val: T[TKey]) => void;
|
1572
1628
|
|
1573
1629
|
/**
|
1574
1630
|
* Creates a new object with the given functions as the prototype and stubs all implemented functions.
|
@@ -1581,14 +1637,15 @@ declare namespace Sinon {
|
|
1581
1637
|
*/
|
1582
1638
|
createStubInstance<TType>(
|
1583
1639
|
constructor: StubbableType<TType>,
|
1584
|
-
overrides?: {
|
1640
|
+
overrides?: {
|
1641
|
+
[K in keyof TType]?:
|
1642
|
+
| SinonStubbedMember<TType[K]>
|
1643
|
+
| (TType[K] extends (...args: any[]) => infer R ? R : TType[K]);
|
1644
|
+
},
|
1585
1645
|
): SinonStubbedInstance<TType>;
|
1586
1646
|
}
|
1587
1647
|
|
1588
1648
|
interface SinonApi {
|
1589
|
-
fake: SinonFake;
|
1590
|
-
match: SinonMatch;
|
1591
|
-
spyCall(...args: any[]): SinonSpyCall;
|
1592
1649
|
expectation: SinonExpectationStatic;
|
1593
1650
|
|
1594
1651
|
clock: {
|
@@ -1606,18 +1663,25 @@ declare namespace Sinon {
|
|
1606
1663
|
*/
|
1607
1664
|
createSandbox(config?: Partial<SinonSandboxConfig>): SinonSandbox;
|
1608
1665
|
defaultConfig: Partial<SinonSandboxConfig>;
|
1609
|
-
}
|
1610
1666
|
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1615
|
-
|
1616
|
-
|
1617
|
-
|
1667
|
+
/**
|
1668
|
+
* Add a custom behavior.
|
1669
|
+
* The name will be available as a function on stubs, and the chaining mechanism
|
1670
|
+
* will be set up for you (e.g. no need to return anything from your function,
|
1671
|
+
* its return value will be ignored). The fn will be passed the fake instance
|
1672
|
+
* as its first argument, and then the user's arguments.
|
1673
|
+
*/
|
1674
|
+
addBehavior: (name: string, fn: (fake: SinonStub, ...userArgs: any[]) => void) => void;
|
1675
|
+
|
1676
|
+
/**
|
1677
|
+
* Replace the default formatter used when formatting ECMAScript object
|
1678
|
+
* An example converts a basic object, such as {id: 42 }, to a string
|
1679
|
+
* on a format of your choosing, such as "{ id: 42 }"
|
1680
|
+
*/
|
1681
|
+
setFormatter: (customFormatter: (...args: any[]) => string) => void;
|
1618
1682
|
}
|
1619
1683
|
|
1620
|
-
type SinonStatic = SinonSandbox &
|
1684
|
+
type SinonStatic = SinonSandbox & SinonApi;
|
1621
1685
|
}
|
1622
1686
|
|
1623
1687
|
declare const Sinon: Sinon.SinonStatic;
|