@discourse/types 0.0.2 → 2026.1.0-a5a0839

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.
Files changed (30) hide show
  1. package/declarations/admin/components/dashboard-new-features.d.ts.map +1 -1
  2. package/declarations/app/components/modal/spreadsheet-editor.d.ts.map +1 -1
  3. package/declarations/app/components/reviewable-refresh/item.d.ts.map +1 -1
  4. package/declarations/app/components/topic-list/bulk-select-checkbox.d.ts +3 -0
  5. package/declarations/app/components/topic-list/bulk-select-checkbox.d.ts.map +1 -0
  6. package/declarations/app/components/topic-list/item/bulk-select-cell.d.ts.map +1 -1
  7. package/declarations/app/components/topic-list/item/topic-cell.d.ts +0 -2
  8. package/declarations/app/components/topic-list/item/topic-cell.d.ts.map +1 -1
  9. package/declarations/app/components/topic-list/item.d.ts.map +1 -1
  10. package/declarations/app/lib/render-tags.d.ts.map +1 -1
  11. package/declarations/tests/helpers/qunit-helpers.d.ts +2 -1
  12. package/declarations/tests/helpers/qunit-helpers.d.ts.map +1 -1
  13. package/declarations/tests/helpers/site-settings.d.ts.map +1 -1
  14. package/declarations/tsconfig.tsbuildinfo +1 -1
  15. package/external-types/@types__jquery/JQuery.d.ts +13440 -0
  16. package/external-types/@types__jquery/JQueryStatic.d.ts +13944 -0
  17. package/external-types/@types__jquery/LICENSE +21 -0
  18. package/external-types/@types__jquery/dist/jquery.slim.d.ts +3 -0
  19. package/external-types/@types__jquery/index.d.ts +7 -0
  20. package/external-types/@types__jquery/legacy.d.ts +204 -0
  21. package/external-types/@types__jquery/misc.d.ts +7388 -0
  22. package/external-types/@types__jquery/package.json +133 -0
  23. package/external-types/@types__sinon/LICENSE +21 -0
  24. package/external-types/@types__sinon/index.d.ts +1468 -0
  25. package/external-types/@types__sinon/package.json +63 -0
  26. package/external-types/pretender/LICENSE +19 -0
  27. package/external-types/pretender/index.d.ts +60 -0
  28. package/external-types/pretender/package.json +75 -0
  29. package/external-types.d.ts +3 -0
  30. package/package.json +1 -1
@@ -0,0 +1,1468 @@
1
+ declare module 'sinon' {
2
+ import * as FakeTimers from "@sinonjs/fake-timers";
3
+
4
+ // sinon uses DOM dependencies which are absent in browser-less environment like node.js
5
+ // to avoid compiler errors this monkey patch is used
6
+ // see more details in https://github.com/DefinitelyTyped/DefinitelyTyped/issues/11351
7
+ interface Event {} // eslint-disable-line @typescript-eslint/no-empty-interface
8
+ interface Document {} // eslint-disable-line @typescript-eslint/no-empty-interface
9
+
10
+ declare namespace Sinon {
11
+ type MatchPartialArguments<T> = {
12
+ [K in keyof T]?: SinonMatcher | (T[K] extends object ? MatchPartialArguments<T[K]> : T[K]);
13
+ };
14
+ // TODO: Alias for backward compatibility, remove on next major release
15
+ type DeepPartialOrMatcher<T> = MatchPartialArguments<T>;
16
+
17
+ type MatchExactArguments<T> = {
18
+ [K in keyof T]: SinonMatcher | (T[K] extends object ? MatchExactArguments<T[K]> : T[K]);
19
+ };
20
+ // TODO: Alias for backward compatibility, remove on next major release
21
+ type MatchArguments<T> = MatchExactArguments<T>;
22
+
23
+ interface SinonSpyCallApi<TArgs extends readonly any[] = any[], TReturnValue = any> {
24
+ // Properties
25
+ /**
26
+ * Array of received arguments.
27
+ */
28
+ args: TArgs;
29
+
30
+ // Methods
31
+ /**
32
+ * Returns true if the spy was called at least once with @param obj as this.
33
+ * calledOn also accepts a matcher spyCall.calledOn(sinon.match(fn)) (see matchers).
34
+ * @param obj
35
+ */
36
+ calledOn(obj: any): boolean;
37
+ /**
38
+ * Returns true if spy was called at least once with the provided arguments.
39
+ * Can be used for partial matching, Sinon only checks the provided arguments against actual arguments,
40
+ * so a call that received the provided arguments (in the same spots) and possibly others as well will return true.
41
+ * @param args
42
+ */
43
+ calledWith(...args: MatchPartialArguments<TArgs>): boolean;
44
+ /**
45
+ * Returns true if spy was called at least once with the provided arguments and no others.
46
+ */
47
+ calledWithExactly(...args: MatchExactArguments<TArgs>): boolean;
48
+ /**
49
+ * Returns true if spy/stub was called the new operator.
50
+ * Beware that this is inferred based on the value of the this object and the spy function’s prototype,
51
+ * so it may give false positives if you actively return the right kind of object.
52
+ */
53
+ calledWithNew(): boolean;
54
+ /**
55
+ * Returns true if spy was called at exactly once with the provided arguments.
56
+ * @param args
57
+ */
58
+ calledOnceWith(...args: MatchPartialArguments<TArgs>): boolean;
59
+ calledOnceWithExactly(...args: MatchExactArguments<TArgs>): boolean;
60
+ /**
61
+ * Returns true if spy was called with matching arguments (and possibly others).
62
+ * This behaves the same as spy.calledWith(sinon.match(arg1), sinon.match(arg2), ...).
63
+ * @param args
64
+ */
65
+ calledWithMatch(...args: MatchPartialArguments<TArgs>): boolean;
66
+ /**
67
+ * Returns true if call did not receive provided arguments.
68
+ * @param args
69
+ */
70
+ notCalledWith(...args: MatchExactArguments<TArgs>): boolean;
71
+ /**
72
+ * Returns true if call did not receive matching arguments.
73
+ * This behaves the same as spyCall.notCalledWith(sinon.match(arg1), sinon.match(arg2), ...).
74
+ * @param args
75
+ */
76
+ notCalledWithMatch(...args: MatchPartialArguments<TArgs>): boolean;
77
+ /**
78
+ * Returns true if spy returned the provided value at least once.
79
+ * Uses deep comparison for objects and arrays. Use spy.returned(sinon.match.same(obj)) for strict comparison (see matchers).
80
+ * @param value
81
+ */
82
+ returned(value: TReturnValue | SinonMatcher): boolean;
83
+ /**
84
+ * Returns true if spy threw an exception at least once.
85
+ */
86
+ threw(): boolean;
87
+ /**
88
+ * Returns true if spy threw an exception of the provided type at least once.
89
+ */
90
+ threw(type: string): boolean;
91
+ /**
92
+ * Returns true if spy threw the provided exception object at least once.
93
+ */
94
+ threw(obj: any): boolean;
95
+ /**
96
+ * Like yield, but with an explicit argument number specifying which callback to call.
97
+ * Useful if a function is called with more than one callback, and simply calling the first callback is not desired.
98
+ * @param pos
99
+ */
100
+ callArg(pos: number): unknown[];
101
+ callArgOn(pos: number, obj: any, ...args: any[]): unknown[];
102
+ /**
103
+ * Like callArg, but with arguments.
104
+ */
105
+ callArgWith(pos: number, ...args: any[]): unknown[];
106
+ callArgOnWith(pos: number, obj: any, ...args: any[]): unknown[];
107
+ /**
108
+ * Invoke callbacks passed to the stub with the given arguments.
109
+ * If the stub was never called with a function argument, yield throws an error.
110
+ * Returns an Array with all callbacks return values in the order they were called, if no error is thrown.
111
+ * Also aliased as invokeCallback.
112
+ */
113
+ yield(...args: any[]): unknown[];
114
+ yieldOn(obj: any, ...args: any[]): unknown[];
115
+ /**
116
+ * Invokes callbacks passed as a property of an object to the stub.
117
+ * Like yield, yieldTo grabs the first matching argument, finds the callback and calls it with the (optional) arguments.
118
+ */
119
+ yieldTo(property: string, ...args: any[]): unknown[];
120
+ yieldToOn(property: string, obj: any, ...args: any[]): unknown[];
121
+ }
122
+
123
+ interface SinonSpyCall<TArgs extends readonly any[] = any[], TReturnValue = any>
124
+ extends SinonSpyCallApi<TArgs, TReturnValue>
125
+ {
126
+ /**
127
+ * The call’s this value.
128
+ */
129
+ thisValue: any;
130
+ /**
131
+ * Exception thrown, if any.
132
+ */
133
+ exception: any;
134
+ /**
135
+ * Return value.
136
+ */
137
+ returnValue: TReturnValue;
138
+ /**
139
+ * This property is a convenience for a call’s callback.
140
+ * When the last argument in a call is a Function, then callback will reference that. Otherwise it will be undefined.
141
+ */
142
+ callback: Function | undefined;
143
+
144
+ /**
145
+ * This property is a convenience for the first argument of the call.
146
+ */
147
+ firstArg: any;
148
+
149
+ /**
150
+ * This property is a convenience for the last argument of the call.
151
+ */
152
+ lastArg: any;
153
+
154
+ /**
155
+ * Returns true if the spy call occurred before another spy call.
156
+ * @param call
157
+ */
158
+ calledBefore(call: SinonSpyCall<any>): boolean;
159
+ /**
160
+ * Returns true if the spy call occurred after another spy call.
161
+ * @param call
162
+ */
163
+ calledAfter(call: SinonSpyCall<any>): boolean;
164
+ }
165
+
166
+ interface SinonSpy<TArgs extends readonly any[] = any[], TReturnValue = any> extends
167
+ Pick<
168
+ SinonSpyCallApi<TArgs, TReturnValue>,
169
+ Exclude<keyof SinonSpyCallApi<TArgs, TReturnValue>, "args">
170
+ >
171
+ {
172
+ // Properties
173
+ /**
174
+ * The number of recorded calls.
175
+ */
176
+ callCount: number;
177
+ /**
178
+ * true if the spy was called at least once
179
+ */
180
+ called: boolean;
181
+ /**
182
+ * true if the spy was not called
183
+ */
184
+ notCalled: boolean;
185
+ /**
186
+ * true if spy was called exactly once
187
+ */
188
+ calledOnce: boolean;
189
+ /**
190
+ * true if the spy was called exactly twice
191
+ */
192
+ calledTwice: boolean;
193
+ /**
194
+ * true if the spy was called exactly thrice
195
+ */
196
+ calledThrice: boolean;
197
+ /**
198
+ * The first call
199
+ */
200
+ firstCall: SinonSpyCall<TArgs, TReturnValue>;
201
+ /**
202
+ * The second call
203
+ */
204
+ secondCall: SinonSpyCall<TArgs, TReturnValue>;
205
+ /**
206
+ * The third call
207
+ */
208
+ thirdCall: SinonSpyCall<TArgs, TReturnValue>;
209
+ /**
210
+ * The last call
211
+ */
212
+ lastCall: SinonSpyCall<TArgs, TReturnValue>;
213
+ /**
214
+ * Array of this objects, spy.thisValues[0] is the this object for the first call.
215
+ */
216
+ thisValues: any[];
217
+ /**
218
+ * Array of arguments received, spy.args[0] is an array of arguments received in the first call.
219
+ */
220
+ args: TArgs[];
221
+ /**
222
+ * Array of exception objects thrown, spy.exceptions[0] is the exception thrown by the first call.
223
+ * If the call did not throw an error, the value at the call’s location in .exceptions will be undefined.
224
+ */
225
+ exceptions: any[];
226
+ /**
227
+ * Array of return values, spy.returnValues[0] is the return value of the first call.
228
+ * If the call did not explicitly return a value, the value at the call’s location in .returnValues will be undefined.
229
+ */
230
+ returnValues: TReturnValue[];
231
+
232
+ /**
233
+ * Holds a reference to the original method/function this stub has wrapped.
234
+ */
235
+ wrappedMethod: (...args: TArgs) => TReturnValue;
236
+
237
+ // Methods
238
+ (...args: TArgs): TReturnValue;
239
+
240
+ /**
241
+ * Returns true if the spy was called before @param anotherSpy
242
+ * @param anotherSpy
243
+ */
244
+ calledBefore(anotherSpy: SinonSpy<any>): boolean;
245
+ /**
246
+ * Returns true if the spy was called after @param anotherSpy
247
+ * @param anotherSpy
248
+ */
249
+ calledAfter(anotherSpy: SinonSpy<any>): boolean;
250
+ /**
251
+ * Returns true if spy was called before @param anotherSpy, and no spy calls occurred between spy and @param anotherSpy.
252
+ * @param anotherSpy
253
+ */
254
+ calledImmediatelyBefore(anotherSpy: SinonSpy<any>): boolean;
255
+ /**
256
+ * Returns true if spy was called after @param anotherSpy, and no spy calls occurred between @param anotherSpy and spy.
257
+ * @param anotherSpy
258
+ */
259
+ calledImmediatelyAfter(anotherSpy: SinonSpy<any>): boolean;
260
+
261
+ /**
262
+ * Creates a spy that only records calls when the received arguments match those passed to withArgs.
263
+ * This is useful to be more expressive in your assertions, where you can access the spy with the same call.
264
+ * @param args Expected args
265
+ */
266
+ withArgs(...args: MatchPartialArguments<TArgs>): SinonSpy<TArgs, TReturnValue>;
267
+ /**
268
+ * Returns true if the spy was always called with @param obj as this.
269
+ * @param obj
270
+ */
271
+ alwaysCalledOn(obj: any): boolean;
272
+ /**
273
+ * Returns true if spy was always called with the provided arguments (and possibly others).
274
+ */
275
+ alwaysCalledWith(...args: MatchExactArguments<TArgs>): boolean;
276
+ /**
277
+ * Returns true if spy was always called with the exact provided arguments.
278
+ * @param args
279
+ */
280
+ alwaysCalledWithExactly(...args: MatchExactArguments<TArgs>): boolean;
281
+ /**
282
+ * Returns true if spy was always called with matching arguments (and possibly others).
283
+ * This behaves the same as spy.alwaysCalledWith(sinon.match(arg1), sinon.match(arg2), ...).
284
+ * @param args
285
+ */
286
+ alwaysCalledWithMatch(...args: TArgs): boolean;
287
+ /**
288
+ * Returns true if the spy/stub was never called with the provided arguments.
289
+ * @param args
290
+ */
291
+ neverCalledWith(...args: MatchExactArguments<TArgs>): boolean;
292
+ /**
293
+ * Returns true if the spy/stub was never called with matching arguments.
294
+ * This behaves the same as spy.neverCalledWith(sinon.match(arg1), sinon.match(arg2), ...).
295
+ * @param args
296
+ */
297
+ neverCalledWithMatch(...args: TArgs): boolean;
298
+ /**
299
+ * Returns true if spy always threw an exception.
300
+ */
301
+ alwaysThrew(): boolean;
302
+ /**
303
+ * Returns true if spy always threw an exception of the provided type.
304
+ */
305
+ alwaysThrew(type: string): boolean;
306
+ /**
307
+ * Returns true if spy always threw the provided exception object.
308
+ */
309
+ alwaysThrew(obj: any): boolean;
310
+ /**
311
+ * Returns true if spy always returned the provided value.
312
+ * @param obj
313
+ */
314
+ alwaysReturned(obj: any): boolean;
315
+ /**
316
+ * Invoke callbacks passed to the stub with the given arguments.
317
+ * If the stub was never called with a function argument, yield throws an error.
318
+ * Returns an Array with all callbacks return values in the order they were called, if no error is thrown.
319
+ */
320
+ invokeCallback(...args: TArgs): void;
321
+ /**
322
+ * Set the displayName of the spy or stub.
323
+ * @param name
324
+ */
325
+ named(name: string): SinonSpy<TArgs, TReturnValue>;
326
+ /**
327
+ * Returns the nth call.
328
+ * Accessing individual calls helps with more detailed behavior verification when the spy is called more than once.
329
+ * @param n Zero-based index of the spy call.
330
+ */
331
+ getCall(n: number): SinonSpyCall<TArgs, TReturnValue>;
332
+ /**
333
+ * Returns an Array of all calls recorded by the spy.
334
+ */
335
+ getCalls(): Array<SinonSpyCall<TArgs, TReturnValue>>;
336
+ /**
337
+ * Resets the state of a spy.
338
+ */
339
+ resetHistory(): void;
340
+ /**
341
+ * Returns the passed format string with the following replacements performed:
342
+ * * %n - the name of the spy "spy" by default)
343
+ * * %c - the number of times the spy was called, in words ("once", "twice", etc.)
344
+ * * %C - a list of string representations of the calls to the spy, with each call prefixed by a newline and four spaces
345
+ * * %t - a comma-delimited list of this values the spy was called on
346
+ * * %n - the formatted value of the nth argument passed to printf
347
+ * * %* - a comma-delimited list of the (non-format string) arguments passed to printf
348
+ * * %D - a multi-line list of the arguments received by all calls to the spy
349
+ * @param format
350
+ * @param args
351
+ */
352
+ printf(format: string, ...args: any[]): string;
353
+ /**
354
+ * Replaces the spy with the original method. Only available if the spy replaced an existing method.
355
+ */
356
+ restore(): void;
357
+ }
358
+
359
+ interface SinonSpyStatic {
360
+ /**
361
+ * Creates an anonymous function that records arguments, this value, exceptions and return values for all calls.
362
+ */
363
+ (): SinonSpy;
364
+ /**
365
+ * Spies on the provided function
366
+ */
367
+ <F extends (...args: any[]) => any>(func: F): SinonSpy<Parameters<F>, ReturnType<F>>;
368
+ /**
369
+ * Spies on all the object’s methods.
370
+ */
371
+ <T>(obj: T): SinonSpiedInstance<T>;
372
+ /**
373
+ * Creates a spy for object.method and replaces the original method with the spy.
374
+ * An exception is thrown if the property is not already a function.
375
+ * The spy acts exactly like the original method in all cases.
376
+ * The original method can be restored by calling object.method.restore().
377
+ * The returned spy is the function object which replaced the original method. spy === object.method.
378
+ */
379
+ <T, K extends keyof T>(
380
+ obj: T,
381
+ method: K,
382
+ ): T[K] extends (...args: infer TArgs) => infer TReturnValue ? SinonSpy<TArgs, TReturnValue>
383
+ : SinonSpy;
384
+
385
+ <T, K extends keyof T>(obj: T, method: K, types: Array<"get" | "set">): PropertyDescriptor & {
386
+ get: SinonSpy<[], T[K]>;
387
+ set: SinonSpy<[T[K]], void>;
388
+ };
389
+ }
390
+
391
+ type SinonSpiedInstance<T> = {
392
+ [P in keyof T]: SinonSpiedMember<T[P]>;
393
+ };
394
+
395
+ type SinonSpiedMember<T> = T extends (...args: infer TArgs) => infer TReturnValue ? SinonSpy<TArgs, TReturnValue>
396
+ : T;
397
+
398
+ interface SinonStub<TArgs extends readonly any[] = any[], TReturnValue = any>
399
+ extends SinonSpy<TArgs, TReturnValue>
400
+ {
401
+ /**
402
+ * Resets the stub’s behaviour to the default behaviour
403
+ * You can reset behaviour of all stubs using sinon.resetBehavior()
404
+ */
405
+ resetBehavior(): void;
406
+ /**
407
+ * Resets both behaviour and history of the stub.
408
+ * This is equivalent to calling both stub.resetBehavior() and stub.resetHistory()
409
+ * Updated in sinon@2.0.0
410
+ * Since sinon@5.0.0
411
+ * As a convenience, you can apply stub.reset() to all stubs using sinon.reset()
412
+ */
413
+ reset(): void;
414
+
415
+ /**
416
+ * Makes the stub return the provided @param obj value.
417
+ * @param obj
418
+ */
419
+ returns(obj: TReturnValue): SinonStub<TArgs, TReturnValue>;
420
+ /**
421
+ * Causes the stub to return the argument at the provided @param index.
422
+ * stub.returnsArg(0); causes the stub to return the first argument.
423
+ * If the argument at the provided index is not available, prior to sinon@6.1.2, an undefined value will be returned;
424
+ * starting from sinon@6.1.2, a TypeError will be thrown.
425
+ * @param index
426
+ */
427
+ returnsArg(index: number): SinonStub<TArgs, TReturnValue>;
428
+ /**
429
+ * Causes the stub to return its this value.
430
+ * Useful for stubbing jQuery-style fluent APIs.
431
+ */
432
+ returnsThis(): SinonStub<TArgs, TReturnValue>;
433
+ /**
434
+ * Causes the stub to return a Promise which resolves to the provided value.
435
+ * When constructing the Promise, sinon uses the Promise.resolve method.
436
+ * You are responsible for providing a polyfill in environments which do not provide Promise.
437
+ * Since sinon@2.0.0
438
+ */
439
+ resolves(
440
+ value?: TReturnValue extends PromiseLike<infer TResolveValue> ? TResolveValue : any,
441
+ ): SinonStub<TArgs, TReturnValue>;
442
+ /**
443
+ * Causes the stub to return a Promise which resolves to the argument at the provided index.
444
+ * stub.resolvesArg(0); causes the stub to return a Promise which resolves to the first argument.
445
+ * If the argument at the provided index is not available, a TypeError will be thrown.
446
+ */
447
+ resolvesArg(index: number): SinonStub<TArgs, TReturnValue>;
448
+ /**
449
+ * Causes the stub to return a Promise which resolves to its this value.
450
+ */
451
+ resolvesThis(): SinonStub<TArgs, TReturnValue>;
452
+ /**
453
+ * Causes the stub to throw an exception (Error).
454
+ * @param type
455
+ */
456
+ throws(type?: string): SinonStub<TArgs, TReturnValue>;
457
+ /**
458
+ * Causes the stub to throw the provided exception object.
459
+ */
460
+ throws(obj: any): SinonStub<TArgs, TReturnValue>;
461
+ /**
462
+ * Causes the stub to throw the argument at the provided index.
463
+ * stub.throwsArg(0); causes the stub to throw the first argument as the exception.
464
+ * If the argument at the provided index is not available, a TypeError will be thrown.
465
+ * Since sinon@2.3.0
466
+ * @param index
467
+ */
468
+ throwsArg(index: number): SinonStub<TArgs, TReturnValue>;
469
+ throwsException(type?: string): SinonStub<TArgs, TReturnValue>;
470
+ throwsException(obj: any): SinonStub<TArgs, TReturnValue>;
471
+ /**
472
+ * Causes the stub to return a Promise which rejects with an exception (Error).
473
+ * When constructing the Promise, sinon uses the Promise.reject method.
474
+ * You are responsible for providing a polyfill in environments which do not provide Promise.
475
+ * Since sinon@2.0.0
476
+ */
477
+ rejects(): SinonStub<TArgs, TReturnValue>;
478
+ /**
479
+ * Causes the stub to return a Promise which rejects with an exception of the provided type.
480
+ * Since sinon@2.0.0
481
+ */
482
+ rejects(errorType: string): SinonStub<TArgs, TReturnValue>;
483
+ /**
484
+ * Causes the stub to return a Promise which rejects with the provided exception object.
485
+ * Since sinon@2.0.0
486
+ */
487
+ rejects(value: any): SinonStub<TArgs, TReturnValue>;
488
+ /**
489
+ * Causes the stub to call the argument at the provided index as a callback function.
490
+ * stub.callsArg(0); causes the stub to call the first argument as a callback.
491
+ * If the argument at the provided index is not available or is not a function, a TypeError will be thrown.
492
+ */
493
+ callsArg(index: number): SinonStub<TArgs, TReturnValue>;
494
+ /**
495
+ * Causes the original method wrapped into the stub to be called when none of the conditional stubs are matched.
496
+ */
497
+ callThrough(): SinonStub<TArgs, TReturnValue>;
498
+ /**
499
+ * Like stub.callsArg(index); but with an additional parameter to pass the this context.
500
+ * @param index
501
+ * @param context
502
+ */
503
+ callsArgOn(index: number, context: any): SinonStub<TArgs, TReturnValue>;
504
+ /**
505
+ * Like callsArg, but with arguments to pass to the callback.
506
+ * @param index
507
+ * @param args
508
+ */
509
+ callsArgWith(index: number, ...args: any[]): SinonStub<TArgs, TReturnValue>;
510
+ /**
511
+ * Like above but with an additional parameter to pass the this context.
512
+ * @param index
513
+ * @param context
514
+ * @param args
515
+ */
516
+ callsArgOnWith(index: number, context: any, ...args: any[]): SinonStub<TArgs, TReturnValue>;
517
+ /**
518
+ * Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
519
+ * In Node environment the callback is deferred with process.nextTick.
520
+ * In a browser the callback is deferred with setTimeout(callback, 0).
521
+ * @param index
522
+ */
523
+ callsArgAsync(index: number): SinonStub<TArgs, TReturnValue>;
524
+ /**
525
+ * Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
526
+ * In Node environment the callback is deferred with process.nextTick.
527
+ * In a browser the callback is deferred with setTimeout(callback, 0).
528
+ * @param index
529
+ * @param context
530
+ */
531
+ callsArgOnAsync(index: number, context: any): SinonStub<TArgs, TReturnValue>;
532
+ /**
533
+ * Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
534
+ * In Node environment the callback is deferred with process.nextTick.
535
+ * In a browser the callback is deferred with setTimeout(callback, 0).
536
+ */
537
+ callsArgWithAsync(index: number, ...args: any[]): SinonStub<TArgs, TReturnValue>;
538
+ /**
539
+ * Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
540
+ * In Node environment the callback is deferred with process.nextTick.
541
+ * In a browser the callback is deferred with setTimeout(callback, 0).
542
+ */
543
+ callsArgOnWithAsync(index: number, context: any, ...args: any[]): SinonStub<TArgs, TReturnValue>;
544
+ /**
545
+ * Makes the stub call the provided @param func when invoked.
546
+ * @param func
547
+ */
548
+ callsFake(func: (...args: TArgs) => TReturnValue): SinonStub<TArgs, TReturnValue>;
549
+ /**
550
+ * Replaces a new getter for this stub.
551
+ */
552
+ get(func: () => any): SinonStub<TArgs, TReturnValue>;
553
+ /**
554
+ * Defines a new setter for this stub.
555
+ * @param func
556
+ */
557
+ set(func: (v: any) => void): SinonStub<TArgs, TReturnValue>;
558
+ /**
559
+ * Defines the behavior of the stub on the @param n call. Useful for testing sequential interactions.
560
+ * There are methods onFirstCall, onSecondCall,onThirdCall to make stub definitions read more naturally.
561
+ * onCall can be combined with all of the behavior defining methods in this section. In particular, it can be used together with withArgs.
562
+ * @param n Zero-based index of the spy call.
563
+ */
564
+ onCall(n: number): SinonStub<TArgs, TReturnValue>;
565
+ /**
566
+ * Alias for stub.onCall(0);
567
+ */
568
+ onFirstCall(): SinonStub<TArgs, TReturnValue>;
569
+ /**
570
+ * Alias for stub.onCall(1);
571
+ */
572
+ onSecondCall(): SinonStub<TArgs, TReturnValue>;
573
+ /**
574
+ * Alias for stub.onCall(2);
575
+ */
576
+ onThirdCall(): SinonStub<TArgs, TReturnValue>;
577
+ /**
578
+ * Defines a new value for this stub.
579
+ * @param val
580
+ */
581
+ value(val: any): SinonStub<TArgs, TReturnValue>;
582
+ /**
583
+ * Set the displayName of the spy or stub.
584
+ * @param name
585
+ */
586
+ named(name: string): SinonStub<TArgs, TReturnValue>;
587
+ /**
588
+ * Similar to callsArg.
589
+ * Causes the stub to call the first callback it receives with the provided arguments (if any).
590
+ * If a method accepts more than one callback, you need to use callsArg to have the stub invoke other callbacks than the first one.
591
+ */
592
+ yields(...args: any[]): SinonStub<TArgs, TReturnValue>;
593
+ /**
594
+ * Like above but with an additional parameter to pass the this context.
595
+ */
596
+ yieldsOn(context: any, ...args: any[]): SinonStub<TArgs, TReturnValue>;
597
+ yieldsRight(...args: any[]): SinonStub<TArgs, TReturnValue>;
598
+ /**
599
+ * Causes the spy to invoke a callback passed as a property of an object to the spy.
600
+ * Like yields, yieldsTo grabs the first matching argument, finds the callback and calls it with the (optional) arguments.
601
+ * @param property
602
+ * @param args
603
+ */
604
+ yieldsTo(property: string, ...args: any[]): SinonStub<TArgs, TReturnValue>;
605
+ /**
606
+ * Like above but with an additional parameter to pass the this context.
607
+ */
608
+ yieldsToOn(property: string, context: any, ...args: any[]): SinonStub<TArgs, TReturnValue>;
609
+ /**
610
+ * Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
611
+ * In Node environment the callback is deferred with process.nextTick.
612
+ * In a browser the callback is deferred with setTimeout(callback, 0).
613
+ * @param args
614
+ */
615
+ yieldsAsync(...args: any[]): SinonStub<TArgs, TReturnValue>;
616
+ /**
617
+ * Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
618
+ * In Node environment the callback is deferred with process.nextTick.
619
+ * In a browser the callback is deferred with setTimeout(callback, 0).
620
+ * @param context
621
+ * @param args
622
+ */
623
+ yieldsOnAsync(context: any, ...args: any[]): SinonStub<TArgs, TReturnValue>;
624
+ /**
625
+ * Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
626
+ * In Node environment the callback is deferred with process.nextTick.
627
+ * In a browser the callback is deferred with setTimeout(callback, 0).
628
+ * @param property
629
+ * @param args
630
+ */
631
+ yieldsToAsync(property: string, ...args: any[]): SinonStub<TArgs, TReturnValue>;
632
+ /**
633
+ * Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed.
634
+ * In Node environment the callback is deferred with process.nextTick.
635
+ * In a browser the callback is deferred with setTimeout(callback, 0).
636
+ * @param property
637
+ * @param context
638
+ * @param args
639
+ */
640
+ yieldsToOnAsync(property: string, context: any, ...args: any[]): SinonStub<TArgs, TReturnValue>;
641
+ /**
642
+ * Stubs the method only for the provided arguments.
643
+ * This is useful to be more expressive in your assertions, where you can access the spy with the same call.
644
+ * It is also useful to create a stub that can act differently in response to different arguments.
645
+ * @param args
646
+ */
647
+ withArgs(...args: MatchPartialArguments<TArgs>): SinonStub<TArgs, TReturnValue>;
648
+ }
649
+
650
+ interface SinonStubStatic {
651
+ /* tslint:disable:no-unnecessary-generics */
652
+
653
+ /**
654
+ * Creates an anonymous stub function
655
+ */
656
+ <TArgs extends readonly any[] = any[], R = any>(): SinonStub<TArgs, R>;
657
+
658
+ /* tslint:enable:no-unnecessary-generics */
659
+
660
+ /**
661
+ * Stubs all the object’s methods.
662
+ * 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).
663
+ * Stubbing individual methods tests intent more precisely and is less susceptible to unexpected behavior as the object’s code evolves.
664
+ * If you want to create a stub object of MyConstructor, but don’t want the constructor to be invoked, use this utility function.
665
+ */
666
+ <T>(obj: T): SinonStubbedInstance<T>;
667
+ /**
668
+ * Replaces obj.method with a stub function.
669
+ * An exception is thrown if the property is not already a function.
670
+ * The original function can be restored by calling object.method.restore(); (or stub.restore();).
671
+ */
672
+ <T, K extends keyof T>(obj: T, method: K): SinonStubbedFunction<T[K]>;
673
+ }
674
+
675
+ interface SinonExpectation extends SinonStub {
676
+ /**
677
+ * Specify the minimum amount of calls expected.
678
+ */
679
+ atLeast(n: number): SinonExpectation;
680
+ /**
681
+ * Specify the maximum amount of calls expected.
682
+ * @param n
683
+ */
684
+ atMost(n: number): SinonExpectation;
685
+ /**
686
+ * Expect the method to never be called.
687
+ */
688
+ never(): SinonExpectation;
689
+ /**
690
+ * Expect the method to be called exactly once.
691
+ */
692
+ once(): SinonExpectation;
693
+ /**
694
+ * Expect the method to be called exactly twice.
695
+ */
696
+ twice(): SinonExpectation;
697
+ /**
698
+ * Expect the method to be called exactly thrice.
699
+ */
700
+ thrice(): SinonExpectation;
701
+ /**
702
+ * Expect the method to be called exactly @param n times.
703
+ */
704
+ exactly(n: number): SinonExpectation;
705
+ /**
706
+ * Expect the method to be called with the provided arguments and possibly others.
707
+ * An expectation instance only holds onto a single set of arguments specified with withArgs.
708
+ * Subsequent calls will overwrite the previously-specified set of arguments (even if they are different),
709
+ * so it is generally not intended that this method be invoked more than once per test case.
710
+ * @param args
711
+ */
712
+ withArgs(...args: any[]): SinonExpectation;
713
+ /**
714
+ * Expect the method to be called with the provided arguments and no others.
715
+ * An expectation instance only holds onto a single set of arguments specified with withExactArgs.
716
+ * Subsequent calls will overwrite the previously-specified set of arguments (even if they are different),
717
+ * so it is generally not intended that this method be invoked more than once per test case.
718
+ * @param args
719
+ */
720
+ withExactArgs(...args: any[]): SinonExpectation;
721
+ on(obj: any): SinonExpectation;
722
+ /**
723
+ * Verifies all expectations on the mock.
724
+ * If any expectation is not satisfied, an exception is thrown.
725
+ * Also restores the mocked methods.
726
+ */
727
+ verify(): SinonExpectation;
728
+ /**
729
+ * Restores all mocked methods.
730
+ */
731
+ restore(): void;
732
+ }
733
+
734
+ interface SinonExpectationStatic {
735
+ /**
736
+ * Creates an expectation without a mock object, basically an anonymous mock function.
737
+ * Method name is optional and is used in exception messages to make them more readable.
738
+ * @param methodName
739
+ */
740
+ create(methodName?: string): SinonExpectation;
741
+ }
742
+
743
+ interface SinonMock {
744
+ /**
745
+ * Overrides obj.method with a mock function and returns it.
746
+ */
747
+ expects(method: string): SinonExpectation;
748
+ /**
749
+ * Restores all mocked methods.
750
+ */
751
+ restore(): void;
752
+ /**
753
+ * Verifies all expectations on the mock.
754
+ * If any expectation is not satisfied, an exception is thrown.
755
+ * Also restores the mocked methods.
756
+ */
757
+ verify(): void;
758
+ }
759
+
760
+ interface SinonMockStatic {
761
+ (name?: string): SinonExpectation;
762
+ /**
763
+ * Creates a mock for the provided object.
764
+ * Does not change the object, but returns a mock object to set expectations on the object’s methods.
765
+ */
766
+ (obj: any): SinonMock;
767
+ }
768
+
769
+ type SinonFakeTimers = FakeTimers.Clock & {
770
+ /**
771
+ * Restores the original clock
772
+ * Identical to uninstall()
773
+ */
774
+ restore(): void;
775
+ };
776
+
777
+ interface SinonFakeUploadProgress {
778
+ eventListeners: {
779
+ progress: any[];
780
+ load: any[];
781
+ abort: any[];
782
+ error: any[];
783
+ };
784
+
785
+ addEventListener(event: string, listener: (e: Event) => any): void;
786
+ removeEventListener(event: string, listener: (e: Event) => any): void;
787
+ dispatchEvent(event: Event): void;
788
+ }
789
+
790
+ interface SinonExposeOptions {
791
+ prefix: string;
792
+ includeFail: boolean;
793
+ }
794
+
795
+ interface SinonAssert {
796
+ // Properties
797
+ /**
798
+ * Every assertion fails by calling this method.
799
+ * If your testing framework of choice looks for assertion errors by checking for a specific exception, you can override the `fail` method to do the right thing.
800
+ */
801
+ fail(message?: string): void; // Overridable
802
+ /**
803
+ * Called every time assertion passes.
804
+ * Default implementation does nothing.
805
+ */
806
+ pass(assertion: any): void; // Overridable
807
+
808
+ // Methods
809
+
810
+ /**
811
+ * Passes if spy was never called
812
+ * @param spy
813
+ */
814
+ notCalled(spy: SinonSpy<any>): void;
815
+ /**
816
+ * Passes if spy was called at least once.
817
+ */
818
+ called(spy: SinonSpy<any>): void;
819
+ /**
820
+ * Passes if spy was called once and only once.
821
+ */
822
+ calledOnce(spy: SinonSpy<any>): void;
823
+ /**
824
+ * Passes if spy was called exactly twice.
825
+ */
826
+ calledTwice(spy: SinonSpy<any>): void;
827
+ /**
828
+ * Passes if spy was called exactly three times.
829
+ */
830
+ calledThrice(spy: SinonSpy<any>): void;
831
+ /**
832
+ * Passes if spy was called exactly num times.
833
+ */
834
+ callCount(spy: SinonSpy<any>, count: number): void;
835
+ /**
836
+ * Passes if provided spies were called in the specified order.
837
+ * @param spies
838
+ */
839
+ callOrder(...spies: Array<SinonSpy<any>>): void;
840
+ /**
841
+ * Passes if spy was ever called with obj as its this value.
842
+ * It’s possible to assert on a dedicated spy call: sinon.assert.calledOn(spy.firstCall, arg1, arg2, ...);.
843
+ */
844
+ calledOn(spyOrSpyCall: SinonSpy<any> | SinonSpyCall<any>, obj: any): void;
845
+ /**
846
+ * Passes if spy was always called with obj as its this value.
847
+ */
848
+ alwaysCalledOn(spy: SinonSpy<any>, obj: any): void;
849
+
850
+ /**
851
+ * Passes if spy was called with the provided arguments.
852
+ * It’s possible to assert on a dedicated spy call: sinon.assert.calledWith(spy.firstCall, arg1, arg2, ...);.
853
+ * @param spyOrSpyCall
854
+ * @param args
855
+ */
856
+ calledWith<TArgs extends any[]>(
857
+ spyOrSpyCall: SinonSpy<TArgs> | SinonSpyCall<TArgs>,
858
+ ...args: MatchPartialArguments<TArgs>
859
+ ): void;
860
+ /**
861
+ * Passes if spy was always called with the provided arguments.
862
+ * @param spy
863
+ * @param args
864
+ */
865
+ alwaysCalledWith<TArgs extends any[]>(spy: SinonSpy<TArgs>, ...args: MatchPartialArguments<TArgs>): void;
866
+ /**
867
+ * Passes if spy was never called with the provided arguments.
868
+ * @param spy
869
+ * @param args
870
+ */
871
+ neverCalledWith<TArgs extends any[]>(spy: SinonSpy<TArgs>, ...args: MatchPartialArguments<TArgs>): void;
872
+ /**
873
+ * Passes if spy was called with the provided arguments and no others.
874
+ * It’s possible to assert on a dedicated spy call: sinon.assert.calledWithExactly(spy.getCall(1), arg1, arg2, ...);.
875
+ * @param spyOrSpyCall
876
+ * @param args
877
+ */
878
+ calledWithExactly<TArgs extends any[]>(
879
+ spyOrSpyCall: SinonSpy<TArgs> | SinonSpyCall<TArgs>,
880
+ ...args: MatchExactArguments<TArgs>
881
+ ): void;
882
+ /**
883
+ * Passes if spy was called at exactly once with the provided arguments and no others.
884
+ * @param spyOrSpyCall
885
+ * @param args
886
+ */
887
+ calledOnceWithExactly<TArgs extends any[]>(
888
+ spyOrSpyCall: SinonSpy<TArgs> | SinonSpyCall<TArgs>,
889
+ ...args: MatchExactArguments<TArgs>
890
+ ): void;
891
+ /**
892
+ * Passes if spy was always called with the provided arguments and no others.
893
+ */
894
+ alwaysCalledWithExactly<TArgs extends any[]>(spy: SinonSpy<TArgs>, ...args: MatchExactArguments<TArgs>): void;
895
+ /**
896
+ * Passes if spy was called with matching arguments.
897
+ * This behaves the same way as sinon.assert.calledWith(spy, sinon.match(arg1), sinon.match(arg2), ...).
898
+ * It's possible to assert on a dedicated spy call: sinon.assert.calledWithMatch(spy.secondCall, arg1, arg2, ...);.
899
+ */
900
+ calledWithMatch<TArgs extends any[]>(
901
+ spyOrSpyCall: SinonSpy<TArgs> | SinonSpyCall<TArgs>,
902
+ ...args: MatchPartialArguments<TArgs>
903
+ ): void;
904
+ /**
905
+ * Passes if spy was called once with matching arguments.
906
+ * This behaves the same way as calling both sinon.assert.calledOnce(spy) and
907
+ * sinon.assert.calledWithMatch(spy, ...).
908
+ */
909
+ calledOnceWithMatch<TArgs extends any[]>(
910
+ spyOrSpyCall: SinonSpy<TArgs> | SinonSpyCall<TArgs>,
911
+ ...args: MatchPartialArguments<TArgs>
912
+ ): void;
913
+ /**
914
+ * Passes if spy was always called with matching arguments.
915
+ * This behaves the same way as sinon.assert.alwaysCalledWith(spy, sinon.match(arg1), sinon.match(arg2), ...).
916
+ */
917
+ alwaysCalledWithMatch<TArgs extends any[]>(spy: SinonSpy<TArgs>, ...args: MatchPartialArguments<TArgs>): void;
918
+ /**
919
+ * Passes if spy was never called with matching arguments.
920
+ * This behaves the same way as sinon.assert.neverCalledWith(spy, sinon.match(arg1), sinon.match(arg2), ...).
921
+ * @param spy
922
+ * @param args
923
+ */
924
+ neverCalledWithMatch<TArgs extends any[]>(spy: SinonSpy<TArgs>, ...args: MatchPartialArguments<TArgs>): void;
925
+ /**
926
+ * Passes if spy was called with the new operator.
927
+ * It’s possible to assert on a dedicated spy call: sinon.assert.calledWithNew(spy.secondCall, arg1, arg2, ...);.
928
+ * @param spyOrSpyCall
929
+ */
930
+ calledWithNew(spyOrSpyCall: SinonSpy<any> | SinonSpyCall<any>): void;
931
+ /**
932
+ * Passes if spy threw any exception.
933
+ */
934
+ threw(spyOrSpyCall: SinonSpy<any> | SinonSpyCall<any>): void;
935
+ /**
936
+ * Passes if spy threw the given exception.
937
+ * The exception is an actual object.
938
+ * It’s possible to assert on a dedicated spy call: sinon.assert.threw(spy.thirdCall, exception);.
939
+ */
940
+ threw(spyOrSpyCall: SinonSpy<any> | SinonSpyCall<any>, exception: string): void;
941
+ /**
942
+ * Passes if spy threw the given exception.
943
+ * The exception is a String denoting its type.
944
+ * It’s possible to assert on a dedicated spy call: sinon.assert.threw(spy.thirdCall, exception);.
945
+ */
946
+ threw(spyOrSpyCall: SinonSpy<any> | SinonSpyCall<any>, exception: any): void;
947
+
948
+ /**
949
+ * Like threw, only required for all calls to the spy.
950
+ */
951
+ alwaysThrew(spy: SinonSpy<any>): void;
952
+ /**
953
+ * Like threw, only required for all calls to the spy.
954
+ */
955
+ alwaysThrew(spy: SinonSpy<any>, exception: string): void;
956
+ /**
957
+ * Like threw, only required for all calls to the spy.
958
+ */
959
+ alwaysThrew(spy: SinonSpy<any>, exception: any): void;
960
+
961
+ /**
962
+ * Uses sinon.match to test if the arguments can be considered a match.
963
+ */
964
+ match(actual: any, expected: any): void;
965
+ /**
966
+ * Exposes assertions into another object, to better integrate with the test framework.
967
+ * For instance, JsTestDriver uses global assertions, and to make Sinon.JS assertions appear alongside them, you can do.
968
+ * @example sinon.assert.expose(this);
969
+ * This will give you assertCalled(spy),assertCallOrder(spy1, spy2, ...) and so on.
970
+ * The method accepts an optional options object with two options.
971
+ */
972
+ expose(obj: any, options?: Partial<SinonExposeOptions>): void;
973
+ }
974
+
975
+ interface SinonMatcher {
976
+ /**
977
+ * All matchers implement and and or. This allows to logically combine mutliple matchers.
978
+ * The result is a new matchers that requires both (and) or one of the matchers (or) to return true.
979
+ * @example var stringOrNumber = sinon.match.string.or(sinon.match.number);
980
+ * var bookWithPages = sinon.match.instanceOf(Book).and(sinon.match.has("pages"));
981
+ */
982
+ and(expr: SinonMatcher): SinonMatcher;
983
+ /**
984
+ * All matchers implement and and or. This allows to logically combine mutliple matchers.
985
+ * The result is a new matchers that requires both (and) or one of the matchers (or) to return true.
986
+ * @example var stringOrNumber = sinon.match.string.or(sinon.match.number);
987
+ * var bookWithPages = sinon.match.instanceOf(Book).and(sinon.match.has("pages"));
988
+ */
989
+ or(expr: SinonMatcher): SinonMatcher;
990
+ test(val: any): boolean;
991
+ }
992
+
993
+ interface SinonArrayMatcher extends SinonMatcher {
994
+ /**
995
+ * Requires an Array to be deep equal another one.
996
+ */
997
+ deepEquals(expected: any[]): SinonMatcher;
998
+ /**
999
+ * Requires an Array to start with the same values as another one.
1000
+ */
1001
+ startsWith(expected: any[]): SinonMatcher;
1002
+ /**
1003
+ * Requires an Array to end with the same values as another one.
1004
+ */
1005
+ endsWith(expected: any[]): SinonMatcher;
1006
+ /**
1007
+ * Requires an Array to contain each one of the values the given array has.
1008
+ */
1009
+ contains(expected: any[]): SinonMatcher;
1010
+ }
1011
+
1012
+ interface SimplifiedSet {
1013
+ has(el: any): boolean;
1014
+ }
1015
+
1016
+ interface SimplifiedMap extends SimplifiedSet {
1017
+ get(key: any): any;
1018
+ }
1019
+
1020
+ interface SinonMapMatcher extends SinonMatcher {
1021
+ /**
1022
+ * Requires a Map to be deep equal another one.
1023
+ */
1024
+ deepEquals(expected: SimplifiedMap): SinonMatcher;
1025
+ /**
1026
+ * Requires a Map to contain each one of the items the given map has.
1027
+ */
1028
+ contains(expected: SimplifiedMap): SinonMatcher;
1029
+ }
1030
+
1031
+ interface SinonSetMatcher extends SinonMatcher {
1032
+ /**
1033
+ * Requires a Set to be deep equal another one.
1034
+ */
1035
+ deepEquals(expected: SimplifiedSet): SinonMatcher;
1036
+ /**
1037
+ * Requires a Set to contain each one of the items the given set has.
1038
+ */
1039
+ contains(expected: SimplifiedSet): SinonMatcher;
1040
+ }
1041
+
1042
+ interface SinonMatch {
1043
+ /**
1044
+ * Requires the value to be == to the given number.
1045
+ */
1046
+ (value: number): SinonMatcher;
1047
+ /**
1048
+ * Requires the value to be a string and have the expectation as a substring.
1049
+ */
1050
+ (value: string): SinonMatcher;
1051
+ /**
1052
+ * Requires the value to be a string and match the given regular expression.
1053
+ */
1054
+ (expr: RegExp): SinonMatcher;
1055
+ /**
1056
+ * See custom matchers.
1057
+ */
1058
+ (callback: (value: any) => boolean, message?: string): SinonMatcher;
1059
+ /**
1060
+ * Requires the value to be not null or undefined and have at least the same properties as expectation.
1061
+ * This supports nested matchers.
1062
+ */
1063
+ (obj: object): SinonMatcher;
1064
+ /**
1065
+ * Matches anything.
1066
+ */
1067
+ any: SinonMatcher;
1068
+ /**
1069
+ * Requires the value to be defined.
1070
+ */
1071
+ defined: SinonMatcher;
1072
+ /**
1073
+ * Requires the value to be truthy.
1074
+ */
1075
+ truthy: SinonMatcher;
1076
+ /**
1077
+ * Requires the value to be falsy.
1078
+ */
1079
+ falsy: SinonMatcher;
1080
+ /**
1081
+ * Requires the value to be a Boolean
1082
+ */
1083
+ bool: SinonMatcher;
1084
+ /**
1085
+ * Requires the value to be a Number.
1086
+ */
1087
+ number: SinonMatcher;
1088
+ /**
1089
+ * Requires the value to be a String.
1090
+ */
1091
+ string: SinonMatcher;
1092
+ /**
1093
+ * Requires the value to be an Object.
1094
+ */
1095
+ object: SinonMatcher;
1096
+ /**
1097
+ * Requires the value to be a Function.
1098
+ */
1099
+ func: SinonMatcher;
1100
+ /**
1101
+ * Requires the value to be a Map.
1102
+ */
1103
+ map: SinonMapMatcher;
1104
+ /**
1105
+ * Requires the value to be a Set.
1106
+ */
1107
+ set: SinonSetMatcher;
1108
+ /**
1109
+ * Requires the value to be an Array.
1110
+ */
1111
+ array: SinonArrayMatcher;
1112
+ /**
1113
+ * Requires the value to be a regular expression.
1114
+ */
1115
+ regexp: SinonMatcher;
1116
+ /**
1117
+ * Requires the value to be a Date object.
1118
+ */
1119
+ date: SinonMatcher;
1120
+ /**
1121
+ * Requires the value to be a Symbol.
1122
+ */
1123
+ symbol: SinonMatcher;
1124
+ /**
1125
+ * Requires the value to be in the specified array.
1126
+ */
1127
+ in(allowed: any[]): SinonMatcher;
1128
+ /**
1129
+ * Requires the value to strictly equal ref.
1130
+ */
1131
+ same(obj: any): SinonMatcher;
1132
+ /**
1133
+ * Requires the value to be of the given type, where type can be one of "undefined", "null", "boolean", "number", "string", "object", "function", "array", "regexp", "date" or "symbol".
1134
+ */
1135
+ typeOf(type: string): SinonMatcher;
1136
+ /**
1137
+ * Requires the value to be an instance of the given type.
1138
+ */
1139
+ instanceOf(type: any): SinonMatcher;
1140
+ /**
1141
+ * Requires the value to define the given property.
1142
+ * The property might be inherited via the prototype chain.
1143
+ * If the optional expectation is given, the value of the property is deeply compared with the expectation.
1144
+ * The expectation can be another matcher.
1145
+ * @param property
1146
+ * @param expect
1147
+ */
1148
+ has(property: string, expect?: any): SinonMatcher;
1149
+ /**
1150
+ * Same as sinon.match.has but the property must be defined by the value itself. Inherited properties are ignored.
1151
+ * @param property
1152
+ * @param expect
1153
+ */
1154
+ hasOwn(property: string, expect?: any): SinonMatcher;
1155
+ /**
1156
+ * Requires the value to define the given propertyPath. Dot (prop.prop) and bracket (prop[0]) notations are supported as in Lodash.get.
1157
+ * The propertyPath might be inherited via the prototype chain.
1158
+ * If the optional expectation is given, the value at the propertyPath is deeply compared with the expectation.
1159
+ * The expectation can be another matcher.
1160
+ */
1161
+ hasNested(path: string, expect?: any): SinonMatcher;
1162
+ /**
1163
+ * Requires every element of an Array, Set or Map, or alternatively every value of an Object to match the given matcher.
1164
+ */
1165
+ every(matcher: SinonMatcher): SinonMatcher;
1166
+ /**
1167
+ * Requires any element of an Array, Set or Map, or alternatively any value of an Object to match the given matcher.
1168
+ */
1169
+ some(matcher: SinonMatcher): SinonMatcher;
1170
+ }
1171
+
1172
+ interface SinonSandboxConfig {
1173
+ /**
1174
+ * The sandbox’s methods can be injected into another object for convenience.
1175
+ * The injectInto configuration option can name an object to add properties to.
1176
+ */
1177
+ injectInto: object | null;
1178
+ /**
1179
+ * Which properties to inject into the facade object. By default empty!
1180
+ */
1181
+ properties: string[];
1182
+ /**
1183
+ * If set to true, the sandbox will have a clock property.
1184
+ * You can optionally pass in a configuration object that follows the specification for fake timers, such as { toFake: ["setTimeout", "setInterval"] }.
1185
+ */
1186
+ useFakeTimers: boolean | Partial<FakeTimers.FakeTimerInstallOpts>;
1187
+ /**
1188
+ * The assert options can help limit the amount of output produced by assert.fail
1189
+ */
1190
+ assertOptions: {
1191
+ shouldLimitAssertionLogs?: boolean;
1192
+ assertionLogLimit?: number;
1193
+ };
1194
+ }
1195
+
1196
+ /**
1197
+ * Stubbed type of an object with members replaced by stubs.
1198
+ *
1199
+ * @template TType Type being stubbed.
1200
+ */
1201
+ type StubbableType<TType> = Function & { prototype: TType };
1202
+
1203
+ /**
1204
+ * An instance of a stubbed object type with functions replaced by stubs.
1205
+ *
1206
+ * @template TType Object type being stubbed.
1207
+ */
1208
+ type SinonStubbedInstance<TType> =
1209
+ & TType
1210
+ & {
1211
+ [P in keyof TType]: SinonStubbedMember<TType[P]>;
1212
+ };
1213
+
1214
+ /**
1215
+ * Replaces a type with a Sinon stub if it's a function.
1216
+ */
1217
+ type SinonStubbedMember<T> = T extends (...args: infer TArgs) => infer TReturnValue ? SinonStub<TArgs, TReturnValue>
1218
+ : T;
1219
+
1220
+ /**
1221
+ * Replaces a function type with a Sinon stub.
1222
+ */
1223
+ type SinonStubbedFunction<T> = T extends (...args: infer TArgs) => infer TReturnValue
1224
+ ? SinonStub<TArgs, TReturnValue>
1225
+ : SinonStub;
1226
+
1227
+ interface SinonFake {
1228
+ /**
1229
+ * Creates a basic fake, with no behavior
1230
+ */
1231
+ <TArgs extends readonly any[] = any[], TReturnValue = any>(): SinonSpy<TArgs, TReturnValue>;
1232
+ /**
1233
+ * Wraps an existing Function to record all interactions, while leaving it up to the func to provide the behavior.
1234
+ * This is useful when complex behavior not covered by the sinon.fake.* methods is required or when wrapping an existing function or method.
1235
+ */
1236
+ <TArgs extends readonly any[] = any[], TReturnValue = any>(fn: (...args: TArgs) => TReturnValue): SinonSpy<
1237
+ TArgs,
1238
+ TReturnValue
1239
+ >;
1240
+ /**
1241
+ * Creates a fake that returns the val argument
1242
+ * @param val Returned value
1243
+ */
1244
+ returns<TArgs extends readonly any[] = any[], TReturnValue = any>(
1245
+ val: TReturnValue,
1246
+ ): SinonSpy<TArgs, TReturnValue>;
1247
+ /**
1248
+ * Creates a fake that throws an Error with the provided value as the message property.
1249
+ * If an Error is passed as the val argument, then that will be the thrown value. If any other value is passed, then that will be used for the message property of the thrown Error.
1250
+ * @param val Returned value or throw value if an Error
1251
+ */
1252
+ throws<TArgs extends readonly any[] = any[], TReturnValue = any>(
1253
+ val: Error | string,
1254
+ ): SinonSpy<TArgs, TReturnValue>;
1255
+ /**
1256
+ * Creates a fake that returns a resolved Promise for the passed value.
1257
+ * @param val Resolved promise
1258
+ */
1259
+ resolves<TArgs extends readonly any[] = any[], TReturnValue = any>(
1260
+ val: TReturnValue extends PromiseLike<infer TResolveValue> ? TResolveValue : any,
1261
+ ): SinonSpy<TArgs, TReturnValue>;
1262
+ /**
1263
+ * Creates a fake that returns a rejected Promise for the passed value.
1264
+ * If an Error is passed as the value argument, then that will be the value of the promise.
1265
+ * If any other value is passed, then that will be used for the message property of the Error returned by the promise.
1266
+ * @param val Rejected promise
1267
+ */
1268
+ rejects<TArgs extends readonly any[] = any[], TReturnValue = any>(val: any): SinonSpy<TArgs, TReturnValue>;
1269
+ /**
1270
+ * fake expects the last argument to be a callback and will invoke it with the given arguments.
1271
+ */
1272
+ yields<TArgs extends readonly any[] = any[], TReturnValue = any>(...args: any[]): SinonSpy<TArgs, TReturnValue>;
1273
+ /**
1274
+ * fake expects the last argument to be a callback and will invoke it asynchronously with the given arguments.
1275
+ */
1276
+ yieldsAsync<TArgs extends readonly any[] = any[], TReturnValue = any>(
1277
+ ...args: any[]
1278
+ ): SinonSpy<TArgs, TReturnValue>;
1279
+ }
1280
+
1281
+ interface SandboxReplace {
1282
+ /**
1283
+ * Replaces property on object with replacement argument.
1284
+ * Attempts to replace an already replaced value cause an exception.
1285
+ * replacement can be any value, including spies, stubs and fakes.
1286
+ * This method only works on non-accessor properties, for replacing accessors,
1287
+ * use sandbox.replaceGetter() and sandbox.replaceSetter().
1288
+ */
1289
+ <T, TKey extends keyof T, R extends T[TKey] = T[TKey]>(obj: T, prop: TKey, replacement: R): R;
1290
+
1291
+ /**
1292
+ * Assigns a value to a property on object with replacement argument.
1293
+ * replacement can be any value, including spies, stubs and fakes.
1294
+ * This method only works on accessor properties.
1295
+ */
1296
+ usingAccessor<T, TKey extends keyof T, R extends T[TKey] = T[TKey]>(obj: T, prop: TKey, replacement: R): R;
1297
+ }
1298
+
1299
+ interface SinonSandbox {
1300
+ /**
1301
+ * A convenience reference for sinon.assert
1302
+ * Since sinon@2.0.0
1303
+ */
1304
+ assert: SinonAssert;
1305
+ clock: SinonFakeTimers;
1306
+ match: SinonMatch;
1307
+ /**
1308
+ * Works exactly like sinon.spy
1309
+ */
1310
+ spy: SinonSpyStatic;
1311
+ /**
1312
+ * Works exactly like sinon.stub.
1313
+ */
1314
+ stub: SinonStubStatic;
1315
+ /**
1316
+ * Works exactly like sinon.mock
1317
+ */
1318
+ mock: SinonMockStatic;
1319
+
1320
+ fake: SinonFake;
1321
+
1322
+ /**
1323
+ * * No param : Causes Sinon to replace the global setTimeout, clearTimeout, setInterval, clearInterval, setImmediate, clearImmediate, process.hrtime, performance.now(when available)
1324
+ * and Date with a custom implementation which is bound to the returned clock object.
1325
+ * Starts the clock at the UNIX epoch (timestamp of 0).
1326
+ * * Now : As above, but rather than starting the clock with a timestamp of 0, start at the provided timestamp now.
1327
+ * Since sinon@2.0.0
1328
+ * You can also pass in a Date object, and its getTime() will be used for the starting timestamp.
1329
+ * * Config : As above, but allows further configuration options, some of which are:
1330
+ * * config.now - Number/Date - installs 'fake-timers' with the specified unix epoch (default: 0)
1331
+ * * config.toFake - String[ ] - an array with explicit function names to fake. By default `fake-timers` will automatically fake _all_ methods (changed in v19).
1332
+ * * config.shouldAdvanceTime - Boolean - tells `fake-timers` to increment mocked time automatically based on the real system time shift (default: false). When used in conjunction with `config.toFake`, it will only work if `'setInterval'` is included in `config.toFake`.
1333
+ * * Important note: when faking `nextTick`, normal calls to `process.nextTick()` will not execute automatically as they would during normal event-loop phases. You would have to call either `clock.next()`, `clock.tick()`, `clock.runAll()` or `clock.runToLast()` manually (see example below). You can easily work around this using the `config.toFake` option. Please refer to the [`fake-timers`](https://github.com/sinonjs/fake-timers) documentation for more information.
1334
+ * @param config
1335
+ */
1336
+ useFakeTimers(config?: number | Date | Partial<FakeTimers.FakeTimerInstallOpts>): SinonFakeTimers;
1337
+ /**
1338
+ * Restores all fakes created through sandbox.
1339
+ */
1340
+ restore(): void;
1341
+ /**
1342
+ * Resets the internal state of all fakes created through sandbox.
1343
+ */
1344
+ reset(): void;
1345
+ /**
1346
+ * Resets the history of all stubs created through the sandbox.
1347
+ * Since sinon@2.0.0
1348
+ */
1349
+ resetHistory(): void;
1350
+ /**
1351
+ * Resets the behaviour of all stubs created through the sandbox.
1352
+ * Since sinon@2.0.0
1353
+ */
1354
+ resetBehavior(): void;
1355
+ /**
1356
+ * Verifies all mocks created through the sandbox.
1357
+ */
1358
+ verify(): void;
1359
+ /**
1360
+ * Verifies all mocks and restores all fakes created through the sandbox.
1361
+ */
1362
+ verifyAndRestore(): void;
1363
+
1364
+ replace: SandboxReplace;
1365
+
1366
+ /**
1367
+ * Replaces getter for property on object with replacement argument. Attempts to replace an already replaced getter cause an exception.
1368
+ * replacement must be a Function, and can be instances of spies, stubs and fakes.
1369
+ * @param obj
1370
+ * @param prop
1371
+ * @param replacement
1372
+ */
1373
+ replaceGetter<T, TKey extends keyof T>(obj: T, prop: TKey, replacement: () => T[TKey]): () => T[TKey];
1374
+
1375
+ /**
1376
+ * Replaces setter for property on object with replacement argument. Attempts to replace an already replaced setter cause an exception.
1377
+ * replacement must be a Function, and can be instances of spies, stubs and fakes.
1378
+ * @param obj
1379
+ * @param prop
1380
+ * @param replacement
1381
+ */
1382
+ replaceSetter<T, TKey extends keyof T>(
1383
+ obj: T,
1384
+ prop: TKey,
1385
+ replacement: (val: T[TKey]) => void,
1386
+ ): (val: T[TKey]) => void;
1387
+
1388
+ /**
1389
+ * Creates a new object with the given functions as the prototype and stubs all implemented functions.
1390
+ *
1391
+ * @template TType Type being stubbed.
1392
+ * @param constructor Object or class to stub.
1393
+ * @param overrides An optional map overriding created stubs
1394
+ * @returns A stubbed version of the constructor.
1395
+ * @remarks The given constructor function is not invoked. See also the stub API.
1396
+ */
1397
+ createStubInstance<TType>(
1398
+ constructor: StubbableType<TType>,
1399
+ overrides?: {
1400
+ [K in keyof TType]?:
1401
+ | SinonStubbedMember<TType[K]>
1402
+ | (TType[K] extends (...args: any[]) => infer R ? R : TType[K]);
1403
+ },
1404
+ ): SinonStubbedInstance<TType>;
1405
+
1406
+ /**
1407
+ * Defines a property on the given object which will be torn down when
1408
+ * the sandbox is restored
1409
+ */
1410
+ define(
1411
+ obj: object,
1412
+ key: PropertyKey,
1413
+ value: unknown,
1414
+ ): void;
1415
+ }
1416
+
1417
+ type SinonPromise<T> = Promise<T> & {
1418
+ status: "pending" | "resolved" | "rejected";
1419
+ resolve(val: unknown): Promise<T>;
1420
+ reject(reason: unknown): Promise<void>;
1421
+ resolvedValue?: T;
1422
+ rejectedValue?: unknown;
1423
+ };
1424
+
1425
+ interface SinonApi {
1426
+ expectation: SinonExpectationStatic;
1427
+
1428
+ clock: {
1429
+ create(now: number | Date): FakeTimers.Clock;
1430
+ };
1431
+
1432
+ /**
1433
+ * Creates a new sandbox object with spies, stubs, and mocks.
1434
+ * @param config
1435
+ */
1436
+ createSandbox(config?: Partial<SinonSandboxConfig>): SinonSandbox;
1437
+ defaultConfig: Partial<SinonSandboxConfig>;
1438
+
1439
+ /**
1440
+ * Add a custom behavior.
1441
+ * The name will be available as a function on stubs, and the chaining mechanism
1442
+ * will be set up for you (e.g. no need to return anything from your function,
1443
+ * its return value will be ignored). The fn will be passed the fake instance
1444
+ * as its first argument, and then the user's arguments.
1445
+ */
1446
+ addBehavior: (name: string, fn: (fake: SinonStub, ...userArgs: any[]) => void) => void;
1447
+
1448
+ /**
1449
+ * Replace the default formatter used when formatting ECMAScript object
1450
+ * An example converts a basic object, such as {id: 42 }, to a string
1451
+ * on a format of your choosing, such as "{ id: 42 }"
1452
+ */
1453
+ setFormatter: (customFormatter: (...args: any[]) => string) => void;
1454
+
1455
+ promise<T = unknown>(
1456
+ executor?: (resolve: (value: T) => void, reject: (reason?: unknown) => void) => void,
1457
+ ): SinonPromise<T>;
1458
+ }
1459
+
1460
+ type SinonStatic = SinonSandbox & SinonApi;
1461
+ }
1462
+
1463
+ declare const Sinon: Sinon.SinonStatic;
1464
+
1465
+ export = Sinon;
1466
+ export as namespace sinon;
1467
+
1468
+ }