UNPKG

86.6 kBTypeScriptView Raw
1import deepEqual = require("deep-eql");
2
3declare global {
4 namespace Chai {
5 type Message = string | (() => string);
6 type ObjectProperty = string | symbol | number;
7
8 interface PathInfo {
9 parent: object;
10 name: string;
11 value?: any;
12 exists: boolean;
13 }
14
15 interface Constructor<T> {
16 new(...args: any[]): T;
17 }
18
19 interface ErrorConstructor {
20 new(...args: any[]): Error;
21 }
22
23 interface ChaiUtils {
24 addChainableMethod(
25 // object to define the method on, e.g. chai.Assertion.prototype
26 ctx: object,
27 // method name
28 name: string,
29 // method itself; any arguments
30 method: (...args: any[]) => void,
31 // called when property is accessed
32 chainingBehavior?: () => void,
33 ): void;
34 overwriteChainableMethod(
35 ctx: object,
36 name: string,
37 method: (...args: any[]) => void,
38 chainingBehavior?: () => void,
39 ): void;
40 addLengthGuard(
41 fn: Function,
42 assertionName: string,
43 isChainable: boolean,
44 ): void;
45 addMethod(ctx: object, name: string, method: Function): void;
46 addProperty(ctx: object, name: string, getter: () => any): void;
47 overwriteMethod(ctx: object, name: string, method: Function): void;
48 overwriteProperty(ctx: object, name: string, getter: (this: AssertionStatic, _super: any) => any): void;
49 compareByInspect(a: object, b: object): -1 | 1;
50 expectTypes(obj: object, types: string[]): void;
51 flag(obj: object, key: string, value?: any): any;
52 getActual(obj: object, args: AssertionArgs): any;
53 getProperties(obj: object): string[];
54 getEnumerableProperties(obj: object): string[];
55 getOwnEnumerablePropertySymbols(obj: object): symbol[];
56 getOwnEnumerableProperties(obj: object): Array<string | symbol>;
57 getMessage(errorLike: Error | string): string;
58 getMessage(obj: any, args: AssertionArgs): string;
59 inspect(obj: any, showHidden?: boolean, depth?: number, colors?: boolean): string;
60 isProxyEnabled(): boolean;
61 objDisplay(obj: object): void;
62 proxify(obj: object, nonChainableMethodName: string): object;
63 test(obj: object, args: AssertionArgs): boolean;
64 transferFlags(assertion: Assertion, obj: object, includeAll?: boolean): void;
65 compatibleInstance(thrown: Error, errorLike: Error | ErrorConstructor): boolean;
66 compatibleConstructor(thrown: Error, errorLike: Error | ErrorConstructor): boolean;
67 compatibleMessage(thrown: Error, errMatcher: string | RegExp): boolean;
68 getConstructorName(constructorFn: Function): string;
69 getFuncName(constructorFn: Function): string | null;
70
71 // Reexports from pathval:
72 hasProperty(obj: object | undefined | null, name: ObjectProperty): boolean;
73 getPathInfo(obj: object, path: string): PathInfo;
74 getPathValue(obj: object, path: string): object | undefined;
75
76 eql: typeof deepEqual;
77 }
78
79 type ChaiPlugin = (chai: ChaiStatic, utils: ChaiUtils) => void;
80
81 interface ChaiStatic {
82 expect: ExpectStatic;
83 should(): Should;
84 /**
85 * Provides a way to extend the internals of Chai
86 */
87 use(fn: ChaiPlugin): ChaiStatic;
88 util: ChaiUtils;
89 assert: AssertStatic;
90 config: Config;
91 Assertion: AssertionStatic;
92 AssertionError: typeof AssertionError;
93 version: string;
94 }
95
96 export interface ExpectStatic {
97 (val: any, message?: string): Assertion;
98 fail(message?: string): never;
99 fail(actual: any, expected: any, message?: string, operator?: Operator): never;
100 }
101
102 export interface AssertStatic extends Assert {
103 }
104
105 // chai.Assertion.prototype.assert arguments
106 type AssertionArgs = [
107 any, // expression to be tested
108 Message, // message or function that returns message to display if expression fails
109 Message, // negatedMessage or function that returns negatedMessage to display if expression fails
110 any?, // expected value
111 any?, // actual value
112 boolean?, // showDiff, when set to `true`, assert will display a diff in addition to the message if expression fails
113 ];
114
115 export interface AssertionPrototype {
116 assert(...args: AssertionArgs): void;
117 _obj: any;
118 }
119
120 export interface AssertionStatic extends AssertionPrototype {
121 prototype: AssertionPrototype;
122
123 new(target: any, message?: string, ssfi?: Function, lockSsfi?: boolean): Assertion;
124
125 // Deprecated properties:
126 includeStack: boolean;
127 showDiff: boolean;
128
129 // Partials of functions on ChaiUtils:
130 addProperty(name: string, getter: (this: AssertionStatic) => any): void;
131 addMethod(name: string, method: (this: AssertionStatic, ...args: any[]) => any): void;
132 addChainableMethod(
133 name: string,
134 method: (this: AssertionStatic, ...args: any[]) => void,
135 chainingBehavior?: () => void,
136 ): void;
137 overwriteProperty(name: string, getter: (this: AssertionStatic, _super: any) => any): void;
138 overwriteMethod(name: string, method: (this: AssertionStatic, ...args: any[]) => any): void;
139 overwriteChainableMethod(
140 name: string,
141 method: (this: AssertionStatic, ...args: any[]) => void,
142 chainingBehavior?: () => void,
143 ): void;
144 }
145
146 export type Operator = string; // "==" | "===" | ">" | ">=" | "<" | "<=" | "!=" | "!==";
147
148 export type OperatorComparable = boolean | null | number | string | undefined | Date;
149
150 interface ShouldAssertion {
151 equal(value1: any, value2: any, message?: string): void;
152 Throw: ShouldThrow;
153 throw: ShouldThrow;
154 exist(value: any, message?: string): void;
155 }
156
157 interface Should extends ShouldAssertion {
158 not: ShouldAssertion;
159 fail(message?: string): never;
160 fail(actual: any, expected: any, message?: string, operator?: Operator): never;
161 }
162
163 interface ShouldThrow {
164 (actual: Function, expected?: string | RegExp, message?: string): void;
165 (actual: Function, constructor: Error | Function, expected?: string | RegExp, message?: string): void;
166 }
167
168 interface Assertion extends LanguageChains, NumericComparison, TypeComparison {
169 not: Assertion;
170 deep: Deep;
171 ordered: Ordered;
172 nested: Nested;
173 own: Own;
174 any: KeyFilter;
175 all: KeyFilter;
176 a: Assertion;
177 an: Assertion;
178 include: Include;
179 includes: Include;
180 contain: Include;
181 contains: Include;
182 ok: Assertion;
183 true: Assertion;
184 false: Assertion;
185 null: Assertion;
186 undefined: Assertion;
187 NaN: Assertion;
188 exist: Assertion;
189 empty: Assertion;
190 arguments: Assertion;
191 Arguments: Assertion;
192 finite: Assertion;
193 equal: Equal;
194 equals: Equal;
195 eq: Equal;
196 eql: Equal;
197 eqls: Equal;
198 containSubset: ContainSubset;
199 property: Property;
200 ownProperty: Property;
201 haveOwnProperty: Property;
202 ownPropertyDescriptor: OwnPropertyDescriptor;
203 haveOwnPropertyDescriptor: OwnPropertyDescriptor;
204 length: Length;
205 lengthOf: Length;
206 match: Match;
207 matches: Match;
208 string(string: string, message?: string): Assertion;
209 keys: Keys;
210 key(string: string): Assertion;
211 throw: Throw;
212 throws: Throw;
213 Throw: Throw;
214 respondTo: RespondTo;
215 respondsTo: RespondTo;
216 itself: Assertion;
217 satisfy: Satisfy;
218 satisfies: Satisfy;
219 closeTo: CloseTo;
220 approximately: CloseTo;
221 members: Members;
222 increase: PropertyChange;
223 increases: PropertyChange;
224 decrease: PropertyChange;
225 decreases: PropertyChange;
226 change: PropertyChange;
227 changes: PropertyChange;
228 extensible: Assertion;
229 sealed: Assertion;
230 frozen: Assertion;
231 oneOf: OneOf;
232 }
233
234 interface LanguageChains {
235 to: Assertion;
236 be: Assertion;
237 been: Assertion;
238 is: Assertion;
239 that: Assertion;
240 which: Assertion;
241 and: Assertion;
242 has: Assertion;
243 have: Assertion;
244 with: Assertion;
245 at: Assertion;
246 of: Assertion;
247 same: Assertion;
248 but: Assertion;
249 does: Assertion;
250 }
251
252 interface NumericComparison {
253 above: NumberComparer;
254 gt: NumberComparer;
255 greaterThan: NumberComparer;
256 least: NumberComparer;
257 gte: NumberComparer;
258 greaterThanOrEqual: NumberComparer;
259 below: NumberComparer;
260 lt: NumberComparer;
261 lessThan: NumberComparer;
262 most: NumberComparer;
263 lte: NumberComparer;
264 lessThanOrEqual: NumberComparer;
265 within(start: number, finish: number, message?: string): Assertion;
266 within(start: Date, finish: Date, message?: string): Assertion;
267 }
268
269 interface NumberComparer {
270 (value: number | Date, message?: string): Assertion;
271 }
272
273 interface TypeComparison {
274 (type: string, message?: string): Assertion;
275 instanceof: InstanceOf;
276 instanceOf: InstanceOf;
277 }
278
279 interface InstanceOf {
280 (constructor: any, message?: string): Assertion;
281 }
282
283 interface CloseTo {
284 (expected: number, delta: number, message?: string): Assertion;
285 }
286
287 interface Nested {
288 include: Include;
289 includes: Include;
290 contain: Include;
291 contains: Include;
292 property: Property;
293 members: Members;
294 }
295
296 interface Own {
297 include: Include;
298 includes: Include;
299 contain: Include;
300 contains: Include;
301 property: Property;
302 }
303
304 interface Deep extends KeyFilter {
305 be: Assertion;
306 equal: Equal;
307 equals: Equal;
308 eq: Equal;
309 include: Include;
310 includes: Include;
311 contain: Include;
312 contains: Include;
313 property: Property;
314 ordered: Ordered;
315 nested: Nested;
316 oneOf: OneOf;
317 own: Own;
318 }
319
320 interface Ordered {
321 members: Members;
322 }
323
324 interface KeyFilter {
325 keys: Keys;
326 members: Members;
327 }
328
329 interface Equal {
330 (value: any, message?: string): Assertion;
331 }
332
333 interface ContainSubset {
334 (expected: any): Assertion;
335 }
336
337 interface Property {
338 (name: string | symbol, value: any, message?: string): Assertion;
339 (name: string | symbol, message?: string): Assertion;
340 }
341
342 interface OwnPropertyDescriptor {
343 (name: string | symbol, descriptor: PropertyDescriptor, message?: string): Assertion;
344 (name: string | symbol, message?: string): Assertion;
345 }
346
347 interface Length extends LanguageChains, NumericComparison {
348 (length: number, message?: string): Assertion;
349 }
350
351 interface Include {
352 (value: any, message?: string): Assertion;
353 keys: Keys;
354 deep: Deep;
355 ordered: Ordered;
356 members: Members;
357 any: KeyFilter;
358 all: KeyFilter;
359 oneOf: OneOf;
360 }
361
362 interface OneOf {
363 (list: readonly unknown[], message?: string): Assertion;
364 }
365
366 interface Match {
367 (regexp: RegExp, message?: string): Assertion;
368 }
369
370 interface Keys {
371 (...keys: string[]): Assertion;
372 (keys: readonly any[] | Object): Assertion;
373 }
374
375 interface Throw {
376 (expected?: string | RegExp, message?: string): Assertion;
377 (constructor: Error | Function, expected?: string | RegExp, message?: string): Assertion;
378 }
379
380 interface RespondTo {
381 (method: string, message?: string): Assertion;
382 }
383
384 interface Satisfy {
385 (matcher: Function, message?: string): Assertion;
386 }
387
388 interface Members {
389 (set: readonly any[], message?: string): Assertion;
390 }
391
392 interface PropertyChange {
393 (object: Object, property?: string, message?: string): DeltaAssertion;
394 }
395
396 interface DeltaAssertion extends Assertion {
397 by(delta: number, msg?: string): Assertion;
398 }
399
400 export interface Assert {
401 /**
402 * @param expression Expression to test for truthiness.
403 * @param message Message to display on error.
404 */
405 (expression: any, message?: string): asserts expression;
406
407 /**
408 * Throws a failure.
409 *
410 * @param message Message to display on error.
411 * @remarks Node.js assert module-compatible.
412 */
413 fail(message?: string): never;
414
415 /**
416 * Throws a failure.
417 *
418 * T Type of the objects.
419 * @param actual Actual value.
420 * @param expected Potential expected value.
421 * @param message Message to display on error.
422 * @param operator Comparison operator, if not strict equality.
423 * @remarks Node.js assert module-compatible.
424 */
425 fail<T>(actual: T, expected: T, message?: string, operator?: Operator): never;
426
427 /**
428 * Asserts that object is truthy.
429 *
430 * @param object Object to test.
431 * @param message Message to display on error.
432 */
433 isOk(value: unknown, message?: string): asserts value;
434
435 /**
436 * Asserts that object is truthy.
437 *
438 * @param object Object to test.
439 * @param message Message to display on error.
440 */
441 ok(value: unknown, message?: string): asserts value;
442
443 /**
444 * Asserts that object is falsy.
445 *
446 * T Type of object.
447 * @param object Object to test.
448 * @param message Message to display on error.
449 */
450 isNotOk<T>(value: T, message?: string): void;
451
452 /**
453 * Asserts that object is falsy.
454 *
455 * T Type of object.
456 * @param object Object to test.
457 * @param message Message to display on error.
458 */
459 notOk<T>(value: T, message?: string): void;
460
461 /**
462 * Asserts non-strict equality (==) of actual and expected.
463 *
464 * T Type of the objects.
465 * @param actual Actual value.
466 * @param expected Potential expected value.
467 * @param message Message to display on error.
468 */
469 equal<T>(actual: T, expected: T, message?: string): void;
470
471 /**
472 * Asserts non-strict inequality (!=) of actual and expected.
473 *
474 * T Type of the objects.
475 * @param actual Actual value.
476 * @param expected Potential expected value.
477 * @param message Message to display on error.
478 */
479 notEqual<T>(actual: T, expected: T, message?: string): void;
480
481 /**
482 * Asserts strict equality (===) of actual and expected.
483 *
484 * T Type of the objects.
485 * @param actual Actual value.
486 * @param expected Potential expected value.
487 * @param message Message to display on error.
488 */
489 strictEqual<T>(actual: T, expected: T, message?: string): void;
490
491 /**
492 * Asserts strict inequality (!==) of actual and expected.
493 *
494 * T Type of the objects.
495 * @param actual Actual value.
496 * @param expected Potential expected value.
497 * @param message Message to display on error.
498 */
499 notStrictEqual<T>(actual: T, expected: T, message?: string): void;
500
501 /**
502 * Asserts that actual is deeply equal to expected.
503 *
504 * T Type of the objects.
505 * @param actual Actual value.
506 * @param expected Potential expected value.
507 * @param message Message to display on error.
508 */
509 deepEqual<T>(actual: T, expected: T, message?: string): void;
510
511 /**
512 * Asserts that actual is not deeply equal to expected.
513 *
514 * T Type of the objects.
515 * @param actual Actual value.
516 * @param expected Potential expected value.
517 * @param message Message to display on error.
518 */
519 notDeepEqual<T>(actual: T, expected: T, message?: string): void;
520
521 /**
522 * Alias to deepEqual
523 *
524 * T Type of the objects.
525 * @param actual Actual value.
526 * @param expected Potential expected value.
527 * @param message Message to display on error.
528 */
529 deepStrictEqual<T>(actual: T, expected: T, message?: string): void;
530
531 /**
532 * Partially matches actual and expected.
533 *
534 * @param actual Actual value.
535 * @param expected Potential subset of the value.
536 * @param message Message to display on error.
537 */
538 containSubset(val: any, exp: any, msg?: string): void;
539
540 /**
541 * Asserts valueToCheck is strictly greater than (>) valueToBeAbove.
542 *
543 * @param valueToCheck Actual value.
544 * @param valueToBeAbove Minimum Potential expected value.
545 * @param message Message to display on error.
546 */
547 isAbove(valueToCheck: number, valueToBeAbove: number, message?: string): void;
548
549 /**
550 * Asserts valueToCheck is greater than or equal to (>=) valueToBeAtLeast.
551 *
552 * @param valueToCheck Actual value.
553 * @param valueToBeAtLeast Minimum Potential expected value.
554 * @param message Message to display on error.
555 */
556 isAtLeast(valueToCheck: number, valueToBeAtLeast: number, message?: string): void;
557
558 /**
559 * Asserts valueToCheck is strictly less than (<) valueToBeBelow.
560 *
561 * @param valueToCheck Actual value.
562 * @param valueToBeBelow Minimum Potential expected value.
563 * @param message Message to display on error.
564 */
565 isBelow(valueToCheck: number, valueToBeBelow: number, message?: string): void;
566
567 /**
568 * Asserts valueToCheck is less than or equal to (<=) valueToBeAtMost.
569 *
570 * @param valueToCheck Actual value.
571 * @param valueToBeAtMost Minimum Potential expected value.
572 * @param message Message to display on error.
573 */
574 isAtMost(valueToCheck: number, valueToBeAtMost: number, message?: string): void;
575
576 /**
577 * Asserts that value is true.
578 *
579 * @param value Actual value.
580 * @param message Message to display on error.
581 */
582 isTrue(value: unknown, message?: string): asserts value is true;
583
584 /**
585 * Asserts that value is false.
586 *
587 * @param value Actual value.
588 * @param message Message to display on error.
589 */
590 isFalse(value: unknown, message?: string): asserts value is false;
591
592 /**
593 * Asserts that value is not true.
594 *
595 * T Type of value.
596 * @param value Actual value.
597 * @param message Message to display on error.
598 */
599 isNotTrue<T>(value: T, message?: string): asserts value is Exclude<T, true>;
600
601 /**
602 * Asserts that value is not false.
603 *
604 * @param value Actual value.
605 * @param message Message to display on error.
606 */
607 isNotFalse<T>(value: T, message?: string): asserts value is Exclude<T, false>;
608
609 /**
610 * Asserts that value is null.
611 *
612 * @param value Actual value.
613 * @param message Message to display on error.
614 */
615 isNull(value: unknown, message?: string): asserts value is null;
616
617 /**
618 * Asserts that value is not null.
619 *
620 * T Type of value.
621 * @param value Actual value.
622 * @param message Message to display on error.
623 */
624 isNotNull<T>(value: T, message?: string): asserts value is Exclude<T, null>;
625
626 /**
627 * Asserts that value is NaN.
628 *
629 * T Type of value.
630 * @param value Actual value.
631 * @param message Message to display on error.
632 */
633 isNaN<T>(value: T, message?: string): void;
634
635 /**
636 * Asserts that value is not NaN.
637 *
638 * T Type of value.
639 * @param value Actual value.
640 * @param message Message to display on error.
641 */
642 isNotNaN<T>(value: T, message?: string): void;
643
644 /**
645 * Asserts that the target is neither null nor undefined.
646 *
647 * T Type of value.
648 * @param value Actual value.
649 * @param message Message to display on error.
650 */
651 exists<T>(value: T, message?: string): asserts value is NonNullable<T>;
652
653 /**
654 * Asserts that the target is either null or undefined.
655 *
656 * @param value Actual value.
657 * @param message Message to display on error.
658 */
659 notExists(value: unknown, message?: string): asserts value is
660 | null
661 | undefined;
662
663 /**
664 * Asserts that value is undefined.
665 *
666 * @param value Actual value.
667 * @param message Message to display on error.
668 */
669 isUndefined(value: unknown, message?: string): asserts value is undefined;
670
671 /**
672 * Asserts that value is not undefined.
673 *
674 * T Type of value.
675 * @param value Actual value.
676 * @param message Message to display on error.
677 */
678 isDefined<T>(value: T, message?: string): asserts value is Exclude<T, undefined>;
679
680 /**
681 * Asserts that value is a function.
682 *
683 * T Type of value.
684 * @param value Actual value.
685 * @param message Message to display on error.
686 */
687 isFunction<T>(value: T, message?: string): void;
688
689 /**
690 * Asserts that value is not a function.
691 *
692 * T Type of value.
693 * @param value Actual value.
694 * @param message Message to display on error.
695 */
696 isNotFunction<T>(value: T, message?: string): void;
697
698 /**
699 * Asserts that value is an object of type 'Object'
700 * (as revealed by Object.prototype.toString).
701 *
702 * T Type of value.
703 * @param value Actual value.
704 * @param message Message to display on error.
705 * @remarks The assertion does not match subclassed objects.
706 */
707 isObject<T>(value: T, message?: string): void;
708
709 /**
710 * Asserts that value is not an object of type 'Object'
711 * (as revealed by Object.prototype.toString).
712 *
713 * T Type of value.
714 * @param value Actual value.
715 * @param message Message to display on error.
716 */
717 isNotObject<T>(value: T, message?: string): void;
718
719 /**
720 * Asserts that value is an array.
721 *
722 * T Type of value.
723 * @param value Actual value.
724 * @param message Message to display on error.
725 */
726 isArray<T>(value: T, message?: string): void;
727
728 /**
729 * Asserts that value is not an array.
730 *
731 * T Type of value.
732 * @param value Actual value.
733 * @param message Message to display on error.
734 */
735 isNotArray<T>(value: T, message?: string): void;
736
737 /**
738 * Asserts that value is a string.
739 *
740 * T Type of value.
741 * @param value Actual value.
742 * @param message Message to display on error.
743 */
744 isString<T>(value: T, message?: string): void;
745
746 /**
747 * Asserts that value is not a string.
748 *
749 * T Type of value.
750 * @param value Actual value.
751 * @param message Message to display on error.
752 */
753 isNotString<T>(value: T, message?: string): void;
754
755 /**
756 * Asserts that value is a number.
757 *
758 * T Type of value.
759 * @param value Actual value.
760 * @param message Message to display on error.
761 */
762 isNumber<T>(value: T, message?: string): void;
763
764 /**
765 * Asserts that value is not a number.
766 *
767 * T Type of value.
768 * @param value Actual value.
769 * @param message Message to display on error.
770 */
771 isNotNumber<T>(value: T, message?: string): void;
772
773 /**
774 * Asserts that value is a finite number.
775 * Unlike `.isNumber`, this will fail for `NaN` and `Infinity`.
776 *
777 * T Type of value
778 * @param value Actual value
779 * @param message Message to display on error.
780 */
781 isFinite<T>(value: T, message?: string): void;
782
783 /**
784 * Asserts that value is a boolean.
785 *
786 * T Type of value.
787 * @param value Actual value.
788 * @param message Message to display on error.
789 */
790 isBoolean<T>(value: T, message?: string): void;
791
792 /**
793 * Asserts that value is not a boolean.
794 *
795 * T Type of value.
796 * @param value Actual value.
797 * @param message Message to display on error.
798 */
799 isNotBoolean<T>(value: T, message?: string): void;
800
801 /**
802 * Asserts that value's type is name, as determined by Object.prototype.toString.
803 *
804 * T Type of value.
805 * @param value Actual value.
806 * @param name Potential expected type name of value.
807 * @param message Message to display on error.
808 */
809 typeOf<T>(value: T, name: string, message?: string): void;
810
811 /**
812 * Asserts that value's type is not name, as determined by Object.prototype.toString.
813 *
814 * T Type of value.
815 * @param value Actual value.
816 * @param name Potential expected type name of value.
817 * @param message Message to display on error.
818 */
819 notTypeOf<T>(value: T, name: string, message?: string): void;
820
821 /**
822 * Asserts that value is an instance of constructor.
823 *
824 * T Expected type of value.
825 * @param value Actual value.
826 * @param constructor Potential expected contructor of value.
827 * @param message Message to display on error.
828 */
829 instanceOf<T>(
830 value: unknown,
831 constructor: Constructor<T>,
832 message?: string,
833 ): asserts value is T;
834
835 /**
836 * Asserts that value is not an instance of constructor.
837 *
838 * T Type of value.
839 * U Type that value shouldn't be an instance of.
840 * @param value Actual value.
841 * @param constructor Potential expected contructor of value.
842 * @param message Message to display on error.
843 */
844 notInstanceOf<T, U>(value: T, type: Constructor<U>, message?: string): asserts value is Exclude<T, U>;
845
846 /**
847 * Asserts that haystack includes needle.
848 *
849 * @param haystack Container string.
850 * @param needle Potential substring of haystack.
851 * @param message Message to display on error.
852 */
853 include(haystack: string, needle: string, message?: string): void;
854
855 /**
856 * Asserts that haystack includes needle.
857 *
858 * T Type of values in haystack.
859 * @param haystack Container array, set or map.
860 * @param needle Potential value contained in haystack.
861 * @param message Message to display on error.
862 */
863 include<T>(
864 haystack: readonly T[] | ReadonlySet<T> | ReadonlyMap<any, T>,
865 needle: T,
866 message?: string,
867 ): void;
868
869 /**
870 * Asserts that haystack includes needle.
871 *
872 * T Type of values in haystack.
873 * @param haystack WeakSet container.
874 * @param needle Potential value contained in haystack.
875 * @param message Message to display on error.
876 */
877 include<T extends object>(haystack: WeakSet<T>, needle: T, message?: string): void;
878
879 /**
880 * Asserts that haystack includes needle.
881 *
882 * T Type of haystack.
883 * @param haystack Object.
884 * @param needle Potential subset of the haystack's properties.
885 * @param message Message to display on error.
886 */
887 include<T>(haystack: T, needle: Partial<T>, message?: string): void;
888
889 /**
890 * Asserts that haystack does not include needle.
891 *
892 * @param haystack Container string.
893 * @param needle Potential substring of haystack.
894 * @param message Message to display on error.
895 */
896 notInclude(haystack: string, needle: string, message?: string): void;
897
898 /**
899 * Asserts that haystack does not include needle.
900 *
901 * T Type of values in haystack.
902 * @param haystack Container array, set or map.
903 * @param needle Potential value contained in haystack.
904 * @param message Message to display on error.
905 */
906 notInclude<T>(
907 haystack: readonly T[] | ReadonlySet<T> | ReadonlyMap<any, T>,
908 needle: T,
909 message?: string,
910 ): void;
911
912 /**
913 * Asserts that haystack does not include needle.
914 *
915 * T Type of values in haystack.
916 * @param haystack WeakSet container.
917 * @param needle Potential value contained in haystack.
918 * @param message Message to display on error.
919 */
920 notInclude<T extends object>(haystack: WeakSet<T>, needle: T, message?: string): void;
921
922 /**
923 * Asserts that haystack does not include needle.
924 *
925 * T Type of haystack.
926 * @param haystack Object.
927 * @param needle Potential subset of the haystack's properties.
928 * @param message Message to display on error.
929 */
930 notInclude<T>(haystack: T, needle: Partial<T>, message?: string): void;
931
932 /**
933 * Asserts that haystack includes needle. Deep equality is used.
934 *
935 * @param haystack Container string.
936 * @param needle Potential substring of haystack.
937 * @param message Message to display on error.
938 *
939 * @deprecated Does not have any effect on string. Use {@link Assert#include} instead.
940 */
941 deepInclude(haystack: string, needle: string, message?: string): void;
942
943 /**
944 * Asserts that haystack includes needle. Deep equality is used.
945 *
946 * T Type of values in haystack.
947 * @param haystack Container array, set or map.
948 * @param needle Potential value contained in haystack.
949 * @param message Message to display on error.
950 */
951 deepInclude<T>(
952 haystack: readonly T[] | ReadonlySet<T> | ReadonlyMap<any, T>,
953 needle: T,
954 message?: string,
955 ): void;
956
957 /**
958 * Asserts that haystack includes needle. Deep equality is used.
959 *
960 * T Type of haystack.
961 * @param haystack Object.
962 * @param needle Potential subset of the haystack's properties.
963 * @param message Message to display on error.
964 */
965 deepInclude<T>(haystack: T, needle: T extends WeakSet<any> ? never : Partial<T>, message?: string): void;
966
967 /**
968 * Asserts that haystack does not include needle. Deep equality is used.
969 *
970 * @param haystack Container string.
971 * @param needle Potential substring of haystack.
972 * @param message Message to display on error.
973 *
974 * @deprecated Does not have any effect on string. Use {@link Assert#notInclude} instead.
975 */
976 notDeepInclude(haystack: string, needle: string, message?: string): void;
977
978 /**
979 * Asserts that haystack does not include needle. Deep equality is used.
980 *
981 * T Type of values in haystack.
982 * @param haystack Container array, set or map.
983 * @param needle Potential value contained in haystack.
984 * @param message Message to display on error.
985 */
986 notDeepInclude<T>(
987 haystack: readonly T[] | ReadonlySet<T> | ReadonlyMap<any, T>,
988 needle: T,
989 message?: string,
990 ): void;
991
992 /**
993 * Asserts that haystack does not include needle. Deep equality is used.
994 *
995 * T Type of haystack.
996 * @param haystack Object.
997 * @param needle Potential subset of the haystack's properties.
998 * @param message Message to display on error.
999 */
1000 notDeepInclude<T>(haystack: T, needle: T extends WeakSet<any> ? never : Partial<T>, message?: string): void;
1001
1002 /**
1003 * Asserts that ‘haystack’ includes ‘needle’. Can be used to assert the inclusion of a subset of properties in an object.
1004 *
1005 * Enables the use of dot- and bracket-notation for referencing nested properties.
1006 * ‘[]’ and ‘.’ in property names can be escaped using double backslashes.Asserts that ‘haystack’ includes ‘needle’.
1007 * Can be used to assert the inclusion of a subset of properties in an object.
1008 * Enables the use of dot- and bracket-notation for referencing nested properties.
1009 * ‘[]’ and ‘.’ in property names can be escaped using double backslashes.
1010 *
1011 * @param haystack
1012 * @param needle
1013 * @param message Message to display on error.
1014 */
1015 nestedInclude(haystack: any, needle: any, message?: string): void;
1016
1017 /**
1018 * Asserts that ‘haystack’ does not include ‘needle’. Can be used to assert the absence of a subset of properties in an object.
1019 *
1020 * Enables the use of dot- and bracket-notation for referencing nested properties.
1021 * ‘[]’ and ‘.’ in property names can be escaped using double backslashes.Asserts that ‘haystack’ includes ‘needle’.
1022 * Can be used to assert the inclusion of a subset of properties in an object.
1023 * Enables the use of dot- and bracket-notation for referencing nested properties.
1024 * ‘[]’ and ‘.’ in property names can be escaped using double backslashes.
1025 *
1026 * @param haystack
1027 * @param needle
1028 * @param message Message to display on error.
1029 */
1030 notNestedInclude(haystack: any, needle: any, message?: string): void;
1031
1032 /**
1033 * Asserts that ‘haystack’ includes ‘needle’. Can be used to assert the inclusion of a subset of properties in an object while checking for deep equality
1034 *
1035 * Enables the use of dot- and bracket-notation for referencing nested properties.
1036 * ‘[]’ and ‘.’ in property names can be escaped using double backslashes.Asserts that ‘haystack’ includes ‘needle’.
1037 * Can be used to assert the inclusion of a subset of properties in an object.
1038 * Enables the use of dot- and bracket-notation for referencing nested properties.
1039 * ‘[]’ and ‘.’ in property names can be escaped using double backslashes.
1040 *
1041 * @param haystack
1042 * @param needle
1043 * @param message Message to display on error.
1044 */
1045 deepNestedInclude(haystack: any, needle: any, message?: string): void;
1046
1047 /**
1048 * Asserts that ‘haystack’ does not include ‘needle’. Can be used to assert the absence of a subset of properties in an object while checking for deep equality.
1049 *
1050 * Enables the use of dot- and bracket-notation for referencing nested properties.
1051 * ‘[]’ and ‘.’ in property names can be escaped using double backslashes.Asserts that ‘haystack’ includes ‘needle’.
1052 * Can be used to assert the inclusion of a subset of properties in an object.
1053 * Enables the use of dot- and bracket-notation for referencing nested properties.
1054 * ‘[]’ and ‘.’ in property names can be escaped using double backslashes.
1055 *
1056 * @param haystack
1057 * @param needle
1058 * @param message Message to display on error.
1059 */
1060 notDeepNestedInclude(haystack: any, needle: any, message?: string): void;
1061
1062 /**
1063 * Asserts that ‘haystack’ includes ‘needle’. Can be used to assert the inclusion of a subset of properties in an object while ignoring inherited properties.
1064 *
1065 * @param haystack
1066 * @param needle
1067 * @param message Message to display on error.
1068 */
1069 ownInclude(haystack: any, needle: any, message?: string): void;
1070
1071 /**
1072 * Asserts that ‘haystack’ includes ‘needle’. Can be used to assert the absence of a subset of properties in an object while ignoring inherited properties.
1073 *
1074 * @param haystack
1075 * @param needle
1076 * @param message Message to display on error.
1077 */
1078 notOwnInclude(haystack: any, needle: any, message?: string): void;
1079
1080 /**
1081 * Asserts that ‘haystack’ includes ‘needle’. Can be used to assert the inclusion of a subset of properties in an object while ignoring inherited properties and checking for deep
1082 *
1083 * @param haystack
1084 * @param needle
1085 * @param message Message to display on error.
1086 */
1087 deepOwnInclude(haystack: any, needle: any, message?: string): void;
1088
1089 /**
1090 * Asserts that ‘haystack’ includes ‘needle’. Can be used to assert the absence of a subset of properties in an object while ignoring inherited properties and checking for deep equality.
1091 *
1092 * @param haystack
1093 * @param needle
1094 * @param message Message to display on error.
1095 */
1096 notDeepOwnInclude(haystack: any, needle: any, message?: string): void;
1097
1098 /**
1099 * Asserts that value matches the regular expression regexp.
1100 *
1101 * @param value Actual value.
1102 * @param regexp Potential match of value.
1103 * @param message Message to display on error.
1104 */
1105 match(value: string, regexp: RegExp, message?: string): void;
1106
1107 /**
1108 * Asserts that value does not match the regular expression regexp.
1109 *
1110 * @param value Actual value.
1111 * @param regexp Potential match of value.
1112 * @param message Message to display on error.
1113 */
1114 notMatch(expected: any, regexp: RegExp, message?: string): void;
1115
1116 /**
1117 * Asserts that object has a property named by property.
1118 *
1119 * T Type of object.
1120 * @param object Container object.
1121 * @param property Potential contained property of object.
1122 * @param message Message to display on error.
1123 */
1124 property<T>(object: T, property: string, /* keyof T */ message?: string): void;
1125
1126 /**
1127 * Asserts that object does not have a property named by property.
1128 *
1129 * T Type of object.
1130 * @param object Container object.
1131 * @param property Potential contained property of object.
1132 * @param message Message to display on error.
1133 */
1134 notProperty<T>(object: T, property: string, /* keyof T */ message?: string): void;
1135
1136 /**
1137 * Asserts that object has a property named by property, which can be a string
1138 * using dot- and bracket-notation for deep reference.
1139 *
1140 * T Type of object.
1141 * @param object Container object.
1142 * @param property Potential contained property of object.
1143 * @param message Message to display on error.
1144 */
1145 deepProperty<T>(object: T, property: string, message?: string): void;
1146
1147 /**
1148 * Asserts that object does not have a property named by property, which can be a
1149 * string using dot- and bracket-notation for deep reference.
1150 *
1151 * T Type of object.
1152 * @param object Container object.
1153 * @param property Potential contained property of object.
1154 * @param message Message to display on error.
1155 */
1156 notDeepProperty<T>(object: T, property: string, message?: string): void;
1157
1158 /**
1159 * Asserts that object has a property named by property with value given by value.
1160 *
1161 * T Type of object.
1162 * V Type of value.
1163 * @param object Container object.
1164 * @param property Potential contained property of object.
1165 * @param value Potential expected property value.
1166 * @param message Message to display on error.
1167 */
1168 propertyVal<T, V>(object: T, property: string, /* keyof T */ value: V, message?: string): void;
1169
1170 /**
1171 * Asserts that object has a property named by property with value given by value.
1172 *
1173 * T Type of object.
1174 * V Type of value.
1175 * @param object Container object.
1176 * @param property Potential contained property of object.
1177 * @param value Potential expected property value.
1178 * @param message Message to display on error.
1179 */
1180 notPropertyVal<T, V>(object: T, property: string, /* keyof T */ value: V, message?: string): void;
1181
1182 /**
1183 * Asserts that object has a property named by property, which can be a string
1184 * using dot- and bracket-notation for deep reference.
1185 *
1186 * T Type of object.
1187 * V Type of value.
1188 * @param object Container object.
1189 * @param property Potential contained property of object.
1190 * @param value Potential expected property value.
1191 * @param message Message to display on error.
1192 */
1193 deepPropertyVal<T, V>(object: T, property: string, value: V, message?: string): void;
1194
1195 /**
1196 * Asserts that object does not have a property named by property, which can be a
1197 * string using dot- and bracket-notation for deep reference.
1198 *
1199 * T Type of object.
1200 * V Type of value.
1201 * @param object Container object.
1202 * @param property Potential contained property of object.
1203 * @param value Potential expected property value.
1204 * @param message Message to display on error.
1205 */
1206 notDeepPropertyVal<T, V>(object: T, property: string, value: V, message?: string): void;
1207
1208 /**
1209 * Asserts that object has a length property with the expected value.
1210 *
1211 * T Type of object.
1212 * @param object Container object.
1213 * @param length Potential expected length of object.
1214 * @param message Message to display on error.
1215 */
1216 lengthOf<T extends { readonly length?: number | undefined } | { readonly size?: number | undefined }>(
1217 object: T,
1218 length: number,
1219 message?: string,
1220 ): void;
1221
1222 /**
1223 * Asserts that fn will throw an error.
1224 *
1225 * @param fn Function that may throw.
1226 * @param errMsgMatcher Expected error message matcher.
1227 * @param ignored Ignored parameter.
1228 * @param message Message to display on error.
1229 */
1230 throw(fn: () => void, errMsgMatcher?: RegExp | string, ignored?: any, message?: string): void;
1231
1232 /**
1233 * Asserts that fn will throw an error.
1234 *
1235 * @param fn Function that may throw.
1236 * @param errorLike Expected error constructor or error instance.
1237 * @param errMsgMatcher Expected error message matcher.
1238 * @param message Message to display on error.
1239 */
1240 throw(
1241 fn: () => void,
1242 errorLike?: ErrorConstructor | Error | null,
1243 errMsgMatcher?: RegExp | string | null,
1244 message?: string,
1245 ): void;
1246
1247 /**
1248 * Asserts that fn will throw an error.
1249 *
1250 * @param fn Function that may throw.
1251 * @param errMsgMatcher Expected error message matcher.
1252 * @param ignored Ignored parameter.
1253 * @param message Message to display on error.
1254 */
1255 throws(fn: () => void, errMsgMatcher?: RegExp | string, ignored?: any, message?: string): void;
1256
1257 /**
1258 * Asserts that fn will throw an error.
1259 *
1260 * @param fn Function that may throw.
1261 * @param errorLike Expected error constructor or error instance.
1262 * @param errMsgMatcher Expected error message matcher.
1263 * @param message Message to display on error.
1264 */
1265 throws(
1266 fn: () => void,
1267 errorLike?: ErrorConstructor | Error | null,
1268 errMsgMatcher?: RegExp | string | null,
1269 message?: string,
1270 ): void;
1271
1272 /**
1273 * Asserts that fn will throw an error.
1274 *
1275 * @param fn Function that may throw.
1276 * @param errMsgMatcher Expected error message matcher.
1277 * @param ignored Ignored parameter.
1278 * @param message Message to display on error.
1279 */
1280 Throw(fn: () => void, errMsgMatcher?: RegExp | string, ignored?: any, message?: string): void;
1281
1282 /**
1283 * Asserts that fn will throw an error.
1284 *
1285 * @param fn Function that may throw.
1286 * @param errorLike Expected error constructor or error instance.
1287 * @param errMsgMatcher Expected error message matcher.
1288 * @param message Message to display on error.
1289 */
1290 Throw(
1291 fn: () => void,
1292 errorLike?: ErrorConstructor | Error | null,
1293 errMsgMatcher?: RegExp | string | null,
1294 message?: string,
1295 ): void;
1296
1297 /**
1298 * Asserts that fn will not throw an error.
1299 *
1300 * @param fn Function that may throw.
1301 * @param errMsgMatcher Expected error message matcher.
1302 * @param ignored Ignored parameter.
1303 * @param message Message to display on error.
1304 */
1305 doesNotThrow(fn: () => void, errMsgMatcher?: RegExp | string, ignored?: any, message?: string): void;
1306
1307 /**
1308 * Asserts that fn will not throw an error.
1309 *
1310 * @param fn Function that may throw.
1311 * @param errorLike Expected error constructor or error instance.
1312 * @param errMsgMatcher Expected error message matcher.
1313 * @param message Message to display on error.
1314 */
1315 doesNotThrow(
1316 fn: () => void,
1317 errorLike?: ErrorConstructor | Error | null,
1318 errMsgMatcher?: RegExp | string | null,
1319 message?: string,
1320 ): void;
1321
1322 /**
1323 * Compares two values using operator.
1324 *
1325 * @param val1 Left value during comparison.
1326 * @param operator Comparison operator.
1327 * @param val2 Right value during comparison.
1328 * @param message Message to display on error.
1329 */
1330 operator(val1: OperatorComparable, operator: Operator, val2: OperatorComparable, message?: string): void;
1331
1332 /**
1333 * Asserts that the target is equal to expected, to within a +/- delta range.
1334 *
1335 * @param actual Actual value
1336 * @param expected Potential expected value.
1337 * @param delta Maximum differenced between values.
1338 * @param message Message to display on error.
1339 */
1340 closeTo(actual: number, expected: number, delta: number, message?: string): void;
1341
1342 /**
1343 * Asserts that the target is equal to expected, to within a +/- delta range.
1344 *
1345 * @param actual Actual value
1346 * @param expected Potential expected value.
1347 * @param delta Maximum differenced between values.
1348 * @param message Message to display on error.
1349 */
1350 approximately(act: number, exp: number, delta: number, message?: string): void;
1351
1352 /**
1353 * Asserts that set1 and set2 have the same members. Order is not take into account.
1354 *
1355 * T Type of set values.
1356 * @param set1 Actual set of values.
1357 * @param set2 Potential expected set of values.
1358 * @param message Message to display on error.
1359 */
1360 sameMembers<T>(set1: T[], set2: T[], message?: string): void;
1361
1362 /**
1363 * Asserts that set1 and set2 have the same members using deep equality checking.
1364 * Order is not take into account.
1365 *
1366 * T Type of set values.
1367 * @param set1 Actual set of values.
1368 * @param set2 Potential expected set of values.
1369 * @param message Message to display on error.
1370 */
1371 sameDeepMembers<T>(set1: T[], set2: T[], message?: string): void;
1372
1373 /**
1374 * Asserts that `set1` and `set2` don't have the same members in any order.
1375 * Uses a deep equality check.
1376 *
1377 * T Type of set values.
1378 * @param set1
1379 * @param set2
1380 * @param message
1381 */
1382 notSameDeepMembers<T>(set1: T[], set2: T[], message?: string): void;
1383
1384 /**
1385 * Asserts that set1 and set2 have the same members in the same order.
1386 * Uses a strict equality check (===).
1387 *
1388 * T Type of set values.
1389 * @param set1 Actual set of values.
1390 * @param set2 Potential expected set of values.
1391 * @param message Message to display on error.
1392 */
1393 sameOrderedMembers<T>(set1: T[], set2: T[], message?: string): void;
1394
1395 /**
1396 * Asserts that set1 and set2 dont have the same members in the same order.
1397 * Uses a strict equality check (===).
1398 *
1399 * T Type of set values.
1400 * @param set1 Actual set of values.
1401 * @param set2 Potential expected set of values.
1402 * @param message Message to display on error.
1403 */
1404 notSameOrderedMembers<T>(set1: T[], set2: T[], message?: string): void;
1405
1406 /**
1407 * Asserts that set1 and set2 have the same members in the same order.
1408 * Uses a deep equality check.
1409 *
1410 * T Type of set values.
1411 * @param set1 Actual set of values.
1412 * @param set2 Potential expected set of values.
1413 * @param message Message to display on error.
1414 */
1415 sameDeepOrderedMembers<T>(set1: T[], set2: T[], message?: string): void;
1416
1417 /**
1418 * Asserts that set1 and set2 dont have the same members in the same order.
1419 * Uses a deep equality check.
1420 *
1421 * T Type of set values.
1422 * @param set1 Actual set of values.
1423 * @param set2 Potential expected set of values.
1424 * @param message Message to display on error.
1425 */
1426 notSameDeepOrderedMembers<T>(set1: T[], set2: T[], message?: string): void;
1427
1428 /**
1429 * Asserts that subset is included in superset in the same order beginning with the first element in superset.
1430 * Uses a strict equality check (===).
1431 *
1432 * T Type of set values.
1433 * @param superset Actual set of values.
1434 * @param subset Potential contained set of values.
1435 * @param message Message to display on error.
1436 */
1437 includeOrderedMembers<T>(superset: T[], subset: T[], message?: string): void;
1438
1439 /**
1440 * Asserts that subset isnt included in superset in the same order beginning with the first element in superset.
1441 * Uses a strict equality check (===).
1442 *
1443 * T Type of set values.
1444 * @param superset Actual set of values.
1445 * @param subset Potential contained set of values.
1446 * @param message Message to display on error.
1447 */
1448 notIncludeOrderedMembers<T>(superset: T[], subset: T[], message?: string): void;
1449
1450 /**
1451 * Asserts that subset is included in superset in the same order beginning with the first element in superset.
1452 * Uses a deep equality check.
1453 *
1454 * T Type of set values.
1455 * @param superset Actual set of values.
1456 * @param subset Potential contained set of values.
1457 * @param message Message to display on error.
1458 */
1459 includeDeepOrderedMembers<T>(superset: T[], subset: T[], message?: string): void;
1460
1461 /**
1462 * Asserts that subset isnt included in superset in the same order beginning with the first element in superset.
1463 * Uses a deep equality check.
1464 *
1465 * T Type of set values.
1466 * @param superset Actual set of values.
1467 * @param subset Potential contained set of values.
1468 * @param message Message to display on error.
1469 */
1470 notIncludeDeepOrderedMembers<T>(superset: T[], subset: T[], message?: string): void;
1471
1472 /**
1473 * Asserts that subset is included in superset. Order is not take into account.
1474 *
1475 * T Type of set values.
1476 * @param superset Actual set of values.
1477 * @param subset Potential contained set of values.
1478 * @param message Message to display on error.
1479 */
1480 includeMembers<T>(superset: T[], subset: T[], message?: string): void;
1481
1482 /**
1483 * Asserts that subset isnt included in superset in any order.
1484 * Uses a strict equality check (===). Duplicates are ignored.
1485 *
1486 * T Type of set values.
1487 * @param superset Actual set of values.
1488 * @param subset Potential not contained set of values.
1489 * @param message Message to display on error.
1490 */
1491 notIncludeMembers<T>(superset: T[], subset: T[], message?: string): void;
1492
1493 /**
1494 * Asserts that subset is included in superset using deep equality checking.
1495 * Order is not take into account.
1496 *
1497 * T Type of set values.
1498 * @param superset Actual set of values.
1499 * @param subset Potential contained set of values.
1500 * @param message Message to display on error.
1501 */
1502 includeDeepMembers<T>(superset: T[], subset: T[], message?: string): void;
1503
1504 /**
1505 * Asserts that `subset` isn't included in `superset` in any order. Uses a
1506 * deep equality check. Duplicates are ignored.
1507 *
1508 * assert.notIncludeDeepMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { b: 2 }, { f: 5 } ], 'not include deep members');
1509 *
1510 * T Type of set values.
1511 * @param superset Actual set of values.
1512 * @param subset Potential contained set of values.
1513 * @param message Message to display on error.
1514 */
1515 notIncludeDeepMembers<T>(superset: T[], subset: T[], message?: string): void;
1516
1517 /**
1518 * Asserts that non-object, non-array value inList appears in the flat array list.
1519 *
1520 * T Type of list values.
1521 * @param inList Value expected to be in the list.
1522 * @param list List of values.
1523 * @param message Message to display on error.
1524 */
1525 oneOf<T>(inList: T, list: T[], message?: string): void;
1526
1527 /**
1528 * Asserts that a function changes the value of a property.
1529 *
1530 * T Type of object.
1531 * @param modifier Function to run.
1532 * @param object Container object.
1533 * @param property Property of object expected to be modified.
1534 * @param message Message to display on error.
1535 */
1536 changes<T>(modifier: Function, object: T, property: string, /* keyof T */ message?: string): void;
1537
1538 /**
1539 * Asserts that a function changes the value of a property by an amount (delta).
1540 *
1541 * @param modifier function
1542 * @param object or getter function
1543 * @param property name _optional_
1544 * @param change amount (delta)
1545 * @param message _optional_
1546 */
1547 changesBy<T>(
1548 modifier: Function,
1549 object: T,
1550 property: string,
1551 /* keyof T */ change: number,
1552 message?: string,
1553 ): void;
1554 changesBy<T>(modifier: Function, object: T, change: number, message?: string): void;
1555
1556 /**
1557 * Asserts that a function does not change the value of a property.
1558 *
1559 * T Type of object.
1560 * @param modifier Function to run.
1561 * @param object Container object.
1562 * @param property Property of object expected not to be modified.
1563 * @param message Message to display on error.
1564 */
1565 doesNotChange<T>(modifier: Function, object: T, property: string, /* keyof T */ message?: string): void;
1566
1567 /**
1568 * Asserts that a function increases an object property.
1569 *
1570 * T Type of object.
1571 * @param modifier Function to run.
1572 * @param object Container object.
1573 * @param property Property of object expected to be increased.
1574 * @param message Message to display on error.
1575 */
1576 increases<T>(modifier: Function, object: T, property: string, /* keyof T */ message?: string): void;
1577
1578 /**
1579 * Asserts that a function increases a numeric object property or a function's return value by an amount (delta).
1580 *
1581 * T Type of object or function.
1582 * @param modifier function
1583 * @param object or getter function
1584 * @param property name _optional_
1585 * @param change amount (delta)
1586 * @param message _optional_
1587 */
1588 increasesBy<T>(
1589 modifier: Function,
1590 object: T,
1591 property: string,
1592 /* keyof T */ change: number,
1593 message?: string,
1594 ): void;
1595 increasesBy<T>(modifier: Function, object: T, change: number, message?: string): void;
1596
1597 /**
1598 * Asserts that a function does not increase an object property.
1599 *
1600 * T Type of object.
1601 * @param modifier Function to run.
1602 * @param object Container object.
1603 * @param property Property of object expected not to be increased.
1604 * @param message Message to display on error.
1605 */
1606 doesNotIncrease<T>(modifier: Function, object: T, property: string, /* keyof T */ message?: string): void;
1607
1608 /**
1609 * Asserts that a function does not increase a numeric object property or function's return value by an amount (delta).
1610 *
1611 * T Type of object or function.
1612 * @param modifier function
1613 * @param object or getter function
1614 * @param property name _optional_
1615 * @param change amount (delta)
1616 * @param message _optional_
1617 */
1618
1619 increasesButNotBy<T>(
1620 modifier: Function,
1621 object: T,
1622 property: string,
1623 /* keyof T */ change: number,
1624 message?: string,
1625 ): void;
1626 increasesButNotBy<T>(modifier: Function, object: T, change: number, message?: string): void;
1627
1628 /**
1629 * Asserts that a function decreases an object property.
1630 *
1631 * T Type of object.
1632 * @param modifier Function to run.
1633 * @param object Container object.
1634 * @param property Property of object expected to be decreased.
1635 * @param message Message to display on error.
1636 */
1637 decreases<T>(modifier: Function, object: T, property: string, /* keyof T */ message?: string): void;
1638
1639 /**
1640 * Asserts that a function decreases a numeric object property or a function's return value by an amount (delta)
1641 *
1642 * T Type of object or function.
1643 * @param modifier function
1644 * @param object or getter function
1645 * @param property name _optional_
1646 * @param change amount (delta)
1647 * @param message _optional_
1648 */
1649
1650 decreasesBy<T>(
1651 modifier: Function,
1652 object: T,
1653 property: string,
1654 /* keyof T */ change: number,
1655 message?: string,
1656 ): void;
1657 decreasesBy<T>(modifier: Function, object: T, change: number, message?: string): void;
1658
1659 /**
1660 * Asserts that a function does not decrease an object property.
1661 *
1662 * T Type of object.
1663 * @param modifier Function to run.
1664 * @param object Container object.
1665 * @param property Property of object expected not to be decreased.
1666 * @param message Message to display on error.
1667 */
1668 doesNotDecrease<T>(modifier: Function, object: T, property: string, /* keyof T */ message?: string): void;
1669
1670 /**
1671 * Asserts that a function does not decreases a numeric object property or a function's return value by an amount (delta)
1672 *
1673 * T Type of object or function.
1674 * @param modifier function
1675 * @param object or getter function
1676 * @param property name _optional_
1677 * @param change amount (delta)
1678 * @param message _optional_
1679 */
1680
1681 doesNotDecreaseBy<T>(
1682 modifier: Function,
1683 object: T,
1684 property: string,
1685 /* keyof T */ change: number,
1686 message?: string,
1687 ): void;
1688 doesNotDecreaseBy<T>(modifier: Function, object: T, change: number, message?: string): void;
1689
1690 /**
1691 * Asserts that a function does not decreases a numeric object property or a function's return value by an amount (delta)
1692 *
1693 * T Type of object or function.
1694 * @param modifier function
1695 * @param object or getter function
1696 * @param property name _optional_
1697 * @param change amount (delta)
1698 * @param message _optional_
1699 */
1700
1701 decreasesButNotBy<T>(
1702 modifier: Function,
1703 object: T,
1704 property: string,
1705 /* keyof T */ change: number,
1706 message?: string,
1707 ): void;
1708 decreasesButNotBy<T>(modifier: Function, object: T, change: number, message?: string): void;
1709
1710 /**
1711 * Asserts if value is not a false value, and throws if it is a true value.
1712 *
1713 * T Type of object.
1714 * @param object Actual value.
1715 * @param message Message to display on error.
1716 * @remarks This is added to allow for chai to be a drop-in replacement for
1717 * Nodes assert class.
1718 */
1719 ifError<T>(object: T, message?: string): void;
1720
1721 /**
1722 * Asserts that object is extensible (can have new properties added to it).
1723 *
1724 * T Type of object
1725 * @param object Actual value.
1726 * @param message Message to display on error.
1727 */
1728 isExtensible<T>(object: T, message?: string): void;
1729
1730 /**
1731 * Asserts that object is extensible (can have new properties added to it).
1732 *
1733 * T Type of object
1734 * @param object Actual value.
1735 * @param message Message to display on error.
1736 */
1737 extensible<T>(object: T, message?: string): void;
1738
1739 /**
1740 * Asserts that object is not extensible.
1741 *
1742 * T Type of object
1743 * @param object Actual value.
1744 * @param message Message to display on error.
1745 */
1746 isNotExtensible<T>(object: T, message?: string): void;
1747
1748 /**
1749 * Asserts that object is not extensible.
1750 *
1751 * T Type of object
1752 * @param object Actual value.
1753 * @param message Message to display on error.
1754 */
1755 notExtensible<T>(object: T, message?: string): void;
1756
1757 /**
1758 * Asserts that object is sealed (can have new properties added to it
1759 * and its existing properties cannot be removed).
1760 *
1761 * T Type of object
1762 * @param object Actual value.
1763 * @param message Message to display on error.
1764 */
1765 isSealed<T>(object: T, message?: string): void;
1766
1767 /**
1768 * Asserts that object is sealed (can have new properties added to it
1769 * and its existing properties cannot be removed).
1770 *
1771 * T Type of object
1772 * @param object Actual value.
1773 * @param message Message to display on error.
1774 */
1775 sealed<T>(object: T, message?: string): void;
1776
1777 /**
1778 * Asserts that object is not sealed.
1779 *
1780 * T Type of object
1781 * @param object Actual value.
1782 * @param message Message to display on error.
1783 */
1784 isNotSealed<T>(object: T, message?: string): void;
1785
1786 /**
1787 * Asserts that object is not sealed.
1788 *
1789 * T Type of object
1790 * @param object Actual value.
1791 * @param message Message to display on error.
1792 */
1793 notSealed<T>(object: T, message?: string): void;
1794
1795 /**
1796 * Asserts that object is frozen (cannot have new properties added to it
1797 * and its existing properties cannot be removed).
1798 *
1799 * T Type of object
1800 * @param object Actual value.
1801 * @param message Message to display on error.
1802 */
1803 isFrozen<T>(object: T, message?: string): void;
1804
1805 /**
1806 * Asserts that object is frozen (cannot have new properties added to it
1807 * and its existing properties cannot be removed).
1808 *
1809 * T Type of object
1810 * @param object Actual value.
1811 * @param message Message to display on error.
1812 */
1813 frozen<T>(object: T, message?: string): void;
1814
1815 /**
1816 * Asserts that object is not frozen (cannot have new properties added to it
1817 * and its existing properties cannot be removed).
1818 *
1819 * T Type of object
1820 * @param object Actual value.
1821 * @param message Message to display on error.
1822 */
1823 isNotFrozen<T>(object: T, message?: string): void;
1824
1825 /**
1826 * Asserts that object is not frozen (cannot have new properties added to it
1827 * and its existing properties cannot be removed).
1828 *
1829 * T Type of object
1830 * @param object Actual value.
1831 * @param message Message to display on error.
1832 */
1833 notFrozen<T>(object: T, message?: string): void;
1834
1835 /**
1836 * Asserts that the target does not contain any values. For arrays and
1837 * strings, it checks the length property. For Map and Set instances, it
1838 * checks the size property. For non-function objects, it gets the count
1839 * of own enumerable string keys.
1840 *
1841 * T Type of object
1842 * @param object Actual value.
1843 * @param message Message to display on error.
1844 */
1845 isEmpty<T>(object: T, message?: string): void;
1846
1847 /**
1848 * Asserts that the target contains values. For arrays and strings, it checks
1849 * the length property. For Map and Set instances, it checks the size property.
1850 * For non-function objects, it gets the count of own enumerable string keys.
1851 *
1852 * T Type of object.
1853 * @param object Object to test.
1854 * @param message Message to display on error.
1855 */
1856 isNotEmpty<T>(object: T, message?: string): void;
1857
1858 /**
1859 * Asserts that `object` has at least one of the `keys` provided.
1860 * You can also provide a single object instead of a `keys` array and its keys
1861 * will be used as the expected set of keys.
1862 *
1863 * T Type of object.
1864 * @param object Object to test.
1865 * @param keys Keys to check
1866 * @param message Message to display on error.
1867 */
1868 hasAnyKeys<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string): void;
1869
1870 /**
1871 * Asserts that `object` has all and only all of the `keys` provided.
1872 * You can also provide a single object instead of a `keys` array and its keys
1873 * will be used as the expected set of keys.
1874 *
1875 * T Type of object.
1876 * @param object Object to test.
1877 * @param keys Keys to check
1878 * @param message Message to display on error.
1879 */
1880 hasAllKeys<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string): void;
1881
1882 /**
1883 * Asserts that `object` has all of the `keys` provided but may have more keys not listed.
1884 * You can also provide a single object instead of a `keys` array and its keys
1885 * will be used as the expected set of keys.
1886 *
1887 * T Type of object.
1888 * @param object Object to test.
1889 * @param keys Keys to check
1890 * @param message Message to display on error.
1891 */
1892 containsAllKeys<T>(
1893 object: T,
1894 keys: Array<Object | string> | { [key: string]: any },
1895 message?: string,
1896 ): void;
1897
1898 /**
1899 * Asserts that `object` has none of the `keys` provided.
1900 * You can also provide a single object instead of a `keys` array and its keys
1901 * will be used as the expected set of keys.
1902 *
1903 * T Type of object.
1904 * @param object Object to test.
1905 * @param keys Keys to check
1906 * @param message Message to display on error.
1907 */
1908 doesNotHaveAnyKeys<T>(
1909 object: T,
1910 keys: Array<Object | string> | { [key: string]: any },
1911 message?: string,
1912 ): void;
1913
1914 /**
1915 * Asserts that `object` does not have at least one of the `keys` provided.
1916 * You can also provide a single object instead of a `keys` array and its keys
1917 * will be used as the expected set of keys.
1918 *
1919 * T Type of object.
1920 * @param object Object to test.
1921 * @param keys Keys to check
1922 * @param message Message to display on error.
1923 */
1924 doesNotHaveAllKeys<T>(
1925 object: T,
1926 keys: Array<Object | string> | { [key: string]: any },
1927 message?: string,
1928 ): void;
1929
1930 /**
1931 * Asserts that `object` has at least one of the `keys` provided.
1932 * Since Sets and Maps can have objects as keys you can use this assertion to perform
1933 * a deep comparison.
1934 * You can also provide a single object instead of a `keys` array and its keys
1935 * will be used as the expected set of keys.
1936 *
1937 * T Type of object.
1938 * @param object Object to test.
1939 * @param keys Keys to check
1940 * @param message Message to display on error.
1941 */
1942 hasAnyDeepKeys<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string): void;
1943
1944 /**
1945 * Asserts that `object` has all and only all of the `keys` provided.
1946 * Since Sets and Maps can have objects as keys you can use this assertion to perform
1947 * a deep comparison.
1948 * You can also provide a single object instead of a `keys` array and its keys
1949 * will be used as the expected set of keys.
1950 *
1951 * T Type of object.
1952 * @param object Object to test.
1953 * @param keys Keys to check
1954 * @param message Message to display on error.
1955 */
1956 hasAllDeepKeys<T>(object: T, keys: Array<Object | string> | { [key: string]: any }, message?: string): void;
1957
1958 /**
1959 * Asserts that `object` contains all of the `keys` provided.
1960 * Since Sets and Maps can have objects as keys you can use this assertion to perform
1961 * a deep comparison.
1962 * You can also provide a single object instead of a `keys` array and its keys
1963 * will be used as the expected set of keys.
1964 *
1965 * T Type of object.
1966 * @param object Object to test.
1967 * @param keys Keys to check
1968 * @param message Message to display on error.
1969 */
1970 containsAllDeepKeys<T>(
1971 object: T,
1972 keys: Array<Object | string> | { [key: string]: any },
1973 message?: string,
1974 ): void;
1975
1976 /**
1977 * Asserts that `object` contains all of the `keys` provided.
1978 * Since Sets and Maps can have objects as keys you can use this assertion to perform
1979 * a deep comparison.
1980 * You can also provide a single object instead of a `keys` array and its keys
1981 * will be used as the expected set of keys.
1982 *
1983 * T Type of object.
1984 * @param object Object to test.
1985 * @param keys Keys to check
1986 * @param message Message to display on error.
1987 */
1988 doesNotHaveAnyDeepKeys<T>(
1989 object: T,
1990 keys: Array<Object | string> | { [key: string]: any },
1991 message?: string,
1992 ): void;
1993
1994 /**
1995 * Asserts that `object` contains all of the `keys` provided.
1996 * Since Sets and Maps can have objects as keys you can use this assertion to perform
1997 * a deep comparison.
1998 * You can also provide a single object instead of a `keys` array and its keys
1999 * will be used as the expected set of keys.
2000 *
2001 * T Type of object.
2002 * @param object Object to test.
2003 * @param keys Keys to check
2004 * @param message Message to display on error.
2005 */
2006 doesNotHaveAllDeepKeys<T>(
2007 object: T,
2008 keys: Array<Object | string> | { [key: string]: any },
2009 message?: string,
2010 ): void;
2011
2012 /**
2013 * Asserts that object has a direct or inherited property named by property,
2014 * which can be a string using dot- and bracket-notation for nested reference.
2015 *
2016 * T Type of object.
2017 * @param object Object to test.
2018 * @param property Property to test.
2019 * @param message Message to display on error.
2020 */
2021 nestedProperty<T>(object: T, property: string, message?: string): void;
2022
2023 /**
2024 * Asserts that object does not have a property named by property,
2025 * which can be a string using dot- and bracket-notation for nested reference.
2026 * The property cannot exist on the object nor anywhere in its prototype chain.
2027 *
2028 * T Type of object.
2029 * @param object Object to test.
2030 * @param property Property to test.
2031 * @param message Message to display on error.
2032 */
2033 notNestedProperty<T>(object: T, property: string, message?: string): void;
2034
2035 /**
2036 * Asserts that object has a property named by property with value given by value.
2037 * property can use dot- and bracket-notation for nested reference. Uses a strict equality check (===).
2038 *
2039 * T Type of object.
2040 * @param object Object to test.
2041 * @param property Property to test.
2042 * @param value Value to test.
2043 * @param message Message to display on error.
2044 */
2045 nestedPropertyVal<T>(object: T, property: string, value: any, message?: string): void;
2046
2047 /**
2048 * Asserts that object does not have a property named by property with value given by value.
2049 * property can use dot- and bracket-notation for nested reference. Uses a strict equality check (===).
2050 *
2051 * T Type of object.
2052 * @param object Object to test.
2053 * @param property Property to test.
2054 * @param value Value to test.
2055 * @param message Message to display on error.
2056 */
2057 notNestedPropertyVal<T>(object: T, property: string, value: any, message?: string): void;
2058
2059 /**
2060 * Asserts that object has a property named by property with a value given by value.
2061 * property can use dot- and bracket-notation for nested reference. Uses a deep equality check.
2062 *
2063 * T Type of object.
2064 * @param object Object to test.
2065 * @param property Property to test.
2066 * @param value Value to test.
2067 * @param message Message to display on error.
2068 */
2069 deepNestedPropertyVal<T>(object: T, property: string, value: any, message?: string): void;
2070
2071 /**
2072 * Asserts that object does not have a property named by property with value given by value.
2073 * property can use dot- and bracket-notation for nested reference. Uses a deep equality check.
2074 *
2075 * T Type of object.
2076 * @param object Object to test.
2077 * @param property Property to test.
2078 * @param value Value to test.
2079 * @param message Message to display on error.
2080 */
2081 notDeepNestedPropertyVal<T>(object: T, property: string, value: any, message?: string): void;
2082 }
2083
2084 export interface Config {
2085 /**
2086 * Default: false
2087 */
2088 includeStack: boolean;
2089
2090 /**
2091 * Default: true
2092 */
2093 showDiff: boolean;
2094
2095 /**
2096 * Default: 40
2097 */
2098 truncateThreshold: number;
2099
2100 /**
2101 * Default: true
2102 */
2103 useProxy: boolean;
2104
2105 /**
2106 * Default: ['then', 'catch', 'inspect', 'toJSON']
2107 */
2108 proxyExcludedKeys: string[];
2109
2110 deepEqual: <L, R>(expected: L, actual: R) => void;
2111 }
2112
2113 export class AssertionError {
2114 constructor(message: string, _props?: any, ssf?: Function);
2115 name: string;
2116 message: string;
2117 showDiff: boolean;
2118 stack: string;
2119 }
2120 }
2121}
2122
2123export function use(fn: Chai.ChaiPlugin): Chai.ChaiStatic;
2124
2125export const util: Chai.ChaiUtils;
2126export const config: Chai.Config;
2127export const Assertion: Chai.AssertionStatic;
2128export function should(): Chai.Should;
2129export function Should(): Chai.Should;
2130export const assert: Chai.AssertStatic;
2131export const expect: Chai.ExpectStatic;
2132
2133declare global {
2134 interface Object {
2135 should: Chai.Assertion;
2136 }
2137}