UNPKG

45.1 kBTypeScriptView Raw
1// Type definitions for chai 3.5.0
2// Project: http://chaijs.com/
3// Definitions by: Jed Mao <https://github.com/jedmao/>,
4// Bart van der Schoor <https://github.com/Bartvds>,
5// Andrew Brown <https://github.com/AGBrown>,
6// Olivier Chevet <https://github.com/olivr70>,
7// Matt Wistrand <https://github.com/mwistrand>,
8// Josh Goldberg <https://github.com/joshuakgoldberg>
9// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
10
11// <reference types="assertion-error"/>
12
13declare namespace Chai {
14
15 interface ChaiStatic {
16 expect: ExpectStatic;
17 should(): Should;
18 /**
19 * Provides a way to extend the internals of Chai
20 */
21 use(fn: (chai: any, utils: any) => void): ChaiStatic;
22 assert: AssertStatic;
23 config: Config;
24 AssertionError: typeof AssertionError;
25 version: string;
26 }
27
28 export interface ExpectStatic extends AssertionStatic {
29 fail(actual?: any, expected?: any, message?: string, operator?: Operator): void;
30 }
31
32 export interface AssertStatic extends Assert {
33 }
34
35 export interface AssertionStatic {
36 (target: any, message?: string): Assertion;
37 }
38
39 export type Operator = string; // "==" | "===" | ">" | ">=" | "<" | "<=" | "!=" | "!==";
40
41 export type OperatorComparable = boolean | null | number | string | undefined | Date;
42
43 interface ShouldAssertion {
44 equal(value1: any, value2: any, message?: string): void;
45 Throw: ShouldThrow;
46 throw: ShouldThrow;
47 exist(value: any, message?: string): void;
48 }
49
50 interface Should extends ShouldAssertion {
51 not: ShouldAssertion;
52 fail(actual: any, expected: any, message?: string, operator?: Operator): void;
53 }
54
55 interface ShouldThrow {
56 (actual: Function): void;
57 (actual: Function, expected: string|RegExp, message?: string): void;
58 (actual: Function, constructor: Error|Function, expected?: string|RegExp, message?: string): void;
59 }
60
61 interface Assertion extends LanguageChains, NumericComparison, TypeComparison {
62 not: Assertion;
63 deep: Deep;
64 any: KeyFilter;
65 all: KeyFilter;
66 a: TypeComparison;
67 an: TypeComparison;
68 include: Include;
69 includes: Include;
70 contain: Include;
71 contains: Include;
72 ok: Assertion;
73 true: Assertion;
74 false: Assertion;
75 null: Assertion;
76 undefined: Assertion;
77 NaN: Assertion;
78 exist: Assertion;
79 empty: Assertion;
80 arguments: Assertion;
81 Arguments: Assertion;
82 equal: Equal;
83 equals: Equal;
84 eq: Equal;
85 eql: Equal;
86 eqls: Equal;
87 property: Property;
88 ownProperty: OwnProperty;
89 haveOwnProperty: OwnProperty;
90 ownPropertyDescriptor: OwnPropertyDescriptor;
91 haveOwnPropertyDescriptor: OwnPropertyDescriptor;
92 length: Length;
93 lengthOf: Length;
94 match: Match;
95 matches: Match;
96 string(string: string, message?: string): Assertion;
97 keys: Keys;
98 key(string: string): Assertion;
99 throw: Throw;
100 throws: Throw;
101 Throw: Throw;
102 respondTo: RespondTo;
103 respondsTo: RespondTo;
104 itself: Assertion;
105 satisfy: Satisfy;
106 satisfies: Satisfy;
107 closeTo: CloseTo;
108 approximately: CloseTo;
109 members: Members;
110 increase: PropertyChange;
111 increases: PropertyChange;
112 decrease: PropertyChange;
113 decreases: PropertyChange;
114 change: PropertyChange;
115 changes: PropertyChange;
116 extensible: Assertion;
117 sealed: Assertion;
118 frozen: Assertion;
119 oneOf(list: any[], message?: string): Assertion;
120 }
121
122 interface LanguageChains {
123 to: Assertion;
124 be: Assertion;
125 been: Assertion;
126 is: Assertion;
127 that: Assertion;
128 which: Assertion;
129 and: Assertion;
130 has: Assertion;
131 have: Assertion;
132 with: Assertion;
133 at: Assertion;
134 of: Assertion;
135 same: Assertion;
136 }
137
138 interface NumericComparison {
139 above: NumberComparer;
140 gt: NumberComparer;
141 greaterThan: NumberComparer;
142 least: NumberComparer;
143 gte: NumberComparer;
144 below: NumberComparer;
145 lt: NumberComparer;
146 lessThan: NumberComparer;
147 most: NumberComparer;
148 lte: NumberComparer;
149 within(start: number, finish: number, message?: string): Assertion;
150 }
151
152 interface NumberComparer {
153 (value: number, message?: string): Assertion;
154 }
155
156 interface TypeComparison {
157 (type: string, message?: string): Assertion;
158 instanceof: InstanceOf;
159 instanceOf: InstanceOf;
160 }
161
162 interface InstanceOf {
163 (constructor: Object, message?: string): Assertion;
164 }
165
166 interface CloseTo {
167 (expected: number, delta: number, message?: string): Assertion;
168 }
169
170 interface Deep {
171 equal: Equal;
172 equals: Equal;
173 eq: Equal;
174 include: Include;
175 property: Property;
176 members: Members;
177 }
178
179 interface KeyFilter {
180 keys: Keys;
181 }
182
183 interface Equal {
184 (value: any, message?: string): Assertion;
185 }
186
187 interface Property {
188 (name: string, value?: any, message?: string): Assertion;
189 }
190
191 interface OwnProperty {
192 (name: string, message?: string): Assertion;
193 }
194
195 interface OwnPropertyDescriptor {
196 (name: string, descriptor: PropertyDescriptor, message?: string): Assertion;
197 (name: string, message?: string): Assertion;
198 }
199
200 interface Length extends LanguageChains, NumericComparison {
201 (length: number, message?: string): Assertion;
202 }
203
204 interface Include {
205 (value: Object, message?: string): Assertion;
206 (value: string, message?: string): Assertion;
207 (value: number, message?: string): Assertion;
208 keys: Keys;
209 members: Members;
210 any: KeyFilter;
211 all: KeyFilter;
212 }
213
214 interface Match {
215 (regexp: RegExp|string, message?: string): Assertion;
216 }
217
218 interface Keys {
219 (...keys: string[]): Assertion;
220 (keys: any[]): Assertion;
221 (keys: Object): Assertion;
222 }
223
224 interface Throw {
225 (): Assertion;
226 (expected: string, message?: string): Assertion;
227 (expected: RegExp, message?: string): Assertion;
228 (constructor: Error, expected?: string, message?: string): Assertion;
229 (constructor: Error, expected?: RegExp, message?: string): Assertion;
230 (constructor: Function, expected?: string, message?: string): Assertion;
231 (constructor: Function, expected?: RegExp, message?: string): Assertion;
232 }
233
234 interface RespondTo {
235 (method: string, message?: string): Assertion;
236 }
237
238 interface Satisfy {
239 (matcher: Function, message?: string): Assertion;
240 }
241
242 interface Members {
243 (set: any[], message?: string): Assertion;
244 }
245
246 interface PropertyChange {
247 (object: Object, property: string, message?: string): Assertion;
248 }
249
250 export interface Assert {
251 /**
252 * @param expression Expression to test for truthiness.
253 * @param message Message to display on error.
254 */
255 (expression: any, message?: string): void;
256
257 /**
258 * Throws a failure.
259 *
260 * @type T Type of the objects.
261 * @param actual Actual value.
262 * @param expected Potential expected value.
263 * @param message Message to display on error.
264 * @param operator Comparison operator, if not strict equality.
265 * @remarks Node.js assert module-compatible.
266 */
267 fail<T>(actual?: T, expected?: T, message?: string, operator?: Operator): void;
268
269 /**
270 * Asserts that object is truthy.
271 *
272 * @type T Type of object.
273 * @param object Object to test.
274 * @param message Message to display on error.
275 */
276 isOk<T>(value: T, message?: string): void;
277
278 /**
279 * Asserts that object is truthy.
280 *
281 * @type T Type of object.
282 * @param object Object to test.
283 * @param message Message to display on error.
284 */
285 ok<T>(value: T, message?: string): void;
286
287 /**
288 * Asserts that object is falsy.
289 *
290 * @type T Type of object.
291 * @param object Object to test.
292 * @param message Message to display on error.
293 */
294 isNotOk<T>(value: T, message?: string): void;
295
296 /**
297 * Asserts that object is falsy.
298 *
299 * @type T Type of object.
300 * @param object Object to test.
301 * @param message Message to display on error.
302 */
303 notOk<T>(value: T, message?: string): void;
304
305 /**
306 * Asserts non-strict equality (==) of actual and expected.
307 *
308 * @type T Type of the objects.
309 * @param actual Actual value.
310 * @param expected Potential expected value.
311 * @param message Message to display on error.
312 */
313 equal<T>(actual: T, expected: T, message?: string): void;
314
315 /**
316 * Asserts non-strict inequality (==) of actual and expected.
317 *
318 * @type T Type of the objects.
319 * @param actual Actual value.
320 * @param expected Potential expected value.
321 * @param message Message to display on error.
322 */
323 notEqual<T>(actual: T, expected: T, message?: string): void;
324
325 /**
326 * Asserts strict equality (===) of actual and expected.
327 *
328 * @type T Type of the objects.
329 * @param actual Actual value.
330 * @param expected Potential expected value.
331 * @param message Message to display on error.
332 */
333 strictEqual<T>(actual: T, expected: T, message?: string): void;
334
335 /**
336 * Asserts strict inequality (==) of actual and expected.
337 *
338 * @type T Type of the objects.
339 * @param actual Actual value.
340 * @param expected Potential expected value.
341 * @param message Message to display on error.
342 */
343 notStrictEqual<T>(actual: T, expected: T, message?: string): void;
344
345 /**
346 * Asserts that actual is deeply equal to expected.
347 *
348 * @type T Type of the objects.
349 * @param actual Actual value.
350 * @param expected Potential expected value.
351 * @param message Message to display on error.
352 */
353 deepEqual<T>(actual: T, expected: T, message?: string): void;
354
355 /**
356 * Asserts that actual is not deeply equal to expected.
357 *
358 * @type T Type of the objects.
359 * @param actual Actual value.
360 * @param expected Potential expected value.
361 * @param message Message to display on error.
362 */
363 notDeepEqual<T>(actual: T, expected: T, message?: string): void;
364
365 /**
366 * Asserts valueToCheck is strictly greater than (>) valueToBeAbove.
367 *
368 * @param valueToCheck Actual value.
369 * @param valueToBeAbove Minimum Potential expected value.
370 * @param message Message to display on error.
371 */
372 isAbove(valueToCheck: number, valueToBeAbove: number, message?: string): void;
373
374 /**
375 * Asserts valueToCheck is greater than or equal to (>=) valueToBeAtLeast.
376 *
377 * @param valueToCheck Actual value.
378 * @param valueToBeAtLeast Minimum Potential expected value.
379 * @param message Message to display on error.
380 */
381 isAtLeast(valueToCheck: number, valueToBeAtLeast: number, message?: string): void;
382
383 /**
384 * Asserts valueToCheck is strictly less than (<) valueToBeBelow.
385 *
386 * @param valueToCheck Actual value.
387 * @param valueToBeBelow Minimum Potential expected value.
388 * @param message Message to display on error.
389 */
390 isBelow(valueToCheck: number, valueToBeBelow: number, message?: string): void;
391
392 /**
393 * Asserts valueToCheck is greater than or equal to (>=) valueToBeAtMost.
394 *
395 * @param valueToCheck Actual value.
396 * @param valueToBeAtMost Minimum Potential expected value.
397 * @param message Message to display on error.
398 */
399 isAtMost(valueToCheck: number, valueToBeAtMost: number, message?: string): void;
400
401 /**
402 * Asserts that value is true.
403 *
404 * @type T Type of value.
405 * @param value Actual value.
406 * @param message Message to display on error.
407 */
408 isTrue<T>(value: T, message?: string): void;
409
410 /**
411 * Asserts that value is false.
412 *
413 * @type T Type of value.
414 * @param value Actual value.
415 * @param message Message to display on error.
416 */
417 isFalse<T>(value: T, message?: string): void;
418
419 /**
420 * Asserts that value is not true.
421 *
422 * @type T Type of value.
423 * @param value Actual value.
424 * @param message Message to display on error.
425 */
426 isNotTrue<T>(value: T, message?: string): void;
427
428 /**
429 * Asserts that value is not false.
430 *
431 * @type T Type of value.
432 * @param value Actual value.
433 * @param message Message to display on error.
434 */
435 isNotFalse<T>(value: T, message?: string): void;
436
437 /**
438 * Asserts that value is null.
439 *
440 * @type T Type of value.
441 * @param value Actual value.
442 * @param message Message to display on error.
443 */
444 isNull<T>(value: T, message?: string): void;
445
446 /**
447 * Asserts that value is not null.
448 *
449 * @type T Type of value.
450 * @param value Actual value.
451 * @param message Message to display on error.
452 */
453 isNotNull<T>(value: T, message?: string): void;
454
455 /**
456 * Asserts that value is not null.
457 *
458 * @type T Type of value.
459 * @param value Actual value.
460 * @param message Message to display on error.
461 */
462 isNaN<T>(value: T, message?: string): void;
463
464 /**
465 * Asserts that value is not null.
466 *
467 * @type T Type of value.
468 * @param value Actual value.
469 * @param message Message to display on error.
470 */
471 isNotNaN<T>(value: T, message?: string): void;
472
473 /**
474 * Asserts that value is undefined.
475 *
476 * @type T Type of value.
477 * @param value Actual value.
478 * @param message Message to display on error.
479 */
480 isUndefined<T>(value: T, message?: string): void;
481
482 /**
483 * Asserts that value is not undefined.
484 *
485 * @type T Type of value.
486 * @param value Actual value.
487 * @param message Message to display on error.
488 */
489 isDefined<T>(value: T, message?: string): void;
490
491 /**
492 * Asserts that value is a function.
493 *
494 * @type T Type of value.
495 * @param value Actual value.
496 * @param message Message to display on error.
497 */
498 isFunction<T>(value: T, message?: string): void;
499
500 /**
501 * Asserts that value is not a function.
502 *
503 * @type T Type of value.
504 * @param value Actual value.
505 * @param message Message to display on error.
506 */
507 isNotFunction<T>(value: T, message?: string): void;
508
509 /**
510 * Asserts that value is an object of type 'Object'
511 * (as revealed by Object.prototype.toString).
512 *
513 * @type T Type of value.
514 * @param value Actual value.
515 * @param message Message to display on error.
516 * @remarks The assertion does not match subclassed objects.
517 */
518 isObject<T>(value: T, message?: string): void;
519
520 /**
521 * Asserts that value is not an object of type 'Object'
522 * (as revealed by Object.prototype.toString).
523 *
524 * @type T Type of value.
525 * @param value Actual value.
526 * @param message Message to display on error.
527 */
528 isNotObject<T>(value: T, message?: string): void;
529
530 /**
531 * Asserts that value is an array.
532 *
533 * @type T Type of value.
534 * @param value Actual value.
535 * @param message Message to display on error.
536 */
537 isArray<T>(value: T, message?: string): void;
538
539 /**
540 * Asserts that value is not an array.
541 *
542 * @type T Type of value.
543 * @param value Actual value.
544 * @param message Message to display on error.
545 */
546 isNotArray<T>(value: T, message?: string): void;
547
548 /**
549 * Asserts that value is a string.
550 *
551 * @type T Type of value.
552 * @param value Actual value.
553 * @param message Message to display on error.
554 */
555 isString<T>(value: T, message?: string): void;
556
557 /**
558 * Asserts that value is not a string.
559 *
560 * @type T Type of value.
561 * @param value Actual value.
562 * @param message Message to display on error.
563 */
564 isNotString<T>(value: T, message?: string): void;
565
566 /**
567 * Asserts that value is a number.
568 *
569 * @type T Type of value.
570 * @param value Actual value.
571 * @param message Message to display on error.
572 */
573 isNumber<T>(value: T, message?: string): void;
574
575 /**
576 * Asserts that value is not a number.
577 *
578 * @type T Type of value.
579 * @param value Actual value.
580 * @param message Message to display on error.
581 */
582 isNotNumber<T>(value: T, message?: string): void;
583
584 /**
585 * Asserts that value is a boolean.
586 *
587 * @type T Type of value.
588 * @param value Actual value.
589 * @param message Message to display on error.
590 */
591 isBoolean<T>(value: T, message?: string): void;
592
593 /**
594 * Asserts that value is not a boolean.
595 *
596 * @type T Type of value.
597 * @param value Actual value.
598 * @param message Message to display on error.
599 */
600 isNotBoolean<T>(value: T, message?: string): void;
601
602 /**
603 * Asserts that value's type is name, as determined by Object.prototype.toString.
604 *
605 * @type T Type of value.
606 * @param value Actual value.
607 * @param name Potential expected type name of value.
608 * @param message Message to display on error.
609 */
610 typeOf<T>(value: T, name: string, message?: string): void;
611
612 /**
613 * Asserts that value's type is not name, as determined by Object.prototype.toString.
614 *
615 * @type T Type of value.
616 * @param value Actual value.
617 * @param name Potential expected type name of value.
618 * @param message Message to display on error.
619 */
620 notTypeOf<T>(value: T, name: string, message?: string): void;
621
622 /**
623 * Asserts that value is an instance of constructor.
624 *
625 * @type T Type of value.
626 * @param value Actual value.
627 * @param constructor Potential expected contructor of value.
628 * @param message Message to display on error.
629 */
630 instanceOf<T>(value: T, constructor: Function, message?: string): void;
631
632 /**
633 * Asserts that value is not an instance of constructor.
634 *
635 * @type T Type of value.
636 * @param value Actual value.
637 * @param constructor Potential expected contructor of value.
638 * @param message Message to display on error.
639 */
640 notInstanceOf<T>(value: T, type: Function, message?: string): void;
641
642 /**
643 * Asserts that haystack includes needle.
644 *
645 * @param haystack Container string.
646 * @param needle Potential expected substring of haystack.
647 * @param message Message to display on error.
648 */
649 include(haystack: string, needle: string, message?: string): void;
650
651 /**
652 * Asserts that haystack includes needle.
653 *
654 * @type T Type of values in haystack.
655 * @param haystack Container array.
656 * @param needle Potential value contained in haystack.
657 * @param message Message to display on error.
658 */
659 include<T>(haystack: T[], needle: T, message?: string): void;
660
661 /**
662 * Asserts that haystack does not include needle.
663 *
664 * @param haystack Container string.
665 * @param needle Potential expected substring of haystack.
666 * @param message Message to display on error.
667 */
668 notInclude(haystack: string, needle: any, message?: string): void;
669
670 /**
671 * Asserts that haystack does not include needle.
672 *
673 * @type T Type of values in haystack.
674 * @param haystack Container array.
675 * @param needle Potential value contained in haystack.
676 * @param message Message to display on error.
677 */
678 notInclude(haystack: any[], needle: any, message?: string): void;
679
680 /**
681 * Asserts that value matches the regular expression regexp.
682 *
683 * @param value Actual value.
684 * @param regexp Potential match of value.
685 * @param message Message to display on error.
686 */
687 match(value: string, regexp: RegExp, message?: string): void;
688
689 /**
690 * Asserts that value does not match the regular expression regexp.
691 *
692 * @param value Actual value.
693 * @param regexp Potential match of value.
694 * @param message Message to display on error.
695 */
696 notMatch(expected: any, regexp: RegExp, message?: string): void;
697
698 /**
699 * Asserts that object has a property named by property.
700 *
701 * @type T Type of object.
702 * @param object Container object.
703 * @param property Potential contained property of object.
704 * @param message Message to display on error.
705 */
706 property<T>(object: T, property: string /* keyof T */, message?: string): void;
707
708 /**
709 * Asserts that object has a property named by property.
710 *
711 * @type T Type of object.
712 * @param object Container object.
713 * @param property Potential contained property of object.
714 * @param message Message to display on error.
715 */
716 notProperty<T>(object: T, property: string /* keyof T */, message?: string): void;
717
718 /**
719 * Asserts that object has a property named by property, which can be a string
720 * using dot- and bracket-notation for deep reference.
721 *
722 * @type T Type of object.
723 * @param object Container object.
724 * @param property Potential contained property of object.
725 * @param message Message to display on error.
726 */
727 deepProperty<T>(object: T, property: string, message?: string): void;
728
729 /**
730 * Asserts that object does not have a property named by property, which can be a
731 * string using dot- and bracket-notation for deep reference.
732 *
733 * @type T Type of object.
734 * @param object Container object.
735 * @param property Potential contained property of object.
736 * @param message Message to display on error.
737 */
738 notDeepProperty<T>(object: T, property: string, message?: string): void;
739
740 /**
741 * Asserts that object has a property named by property with value given by value.
742 *
743 * @type T Type of object.
744 * @type V Type of value.
745 * @param object Container object.
746 * @param property Potential contained property of object.
747 * @param value Potential expected property value.
748 * @param message Message to display on error.
749 */
750 propertyVal<T, V>(object: T, property: string /* keyof T */, value: V, message?: string): void;
751
752 /**
753 * Asserts that object has a property named by property with value given by value.
754 *
755 * @type T Type of object.
756 * @type V Type of value.
757 * @param object Container object.
758 * @param property Potential contained property of object.
759 * @param value Potential expected property value.
760 * @param message Message to display on error.
761 */
762 propertyNotVal<T, V>(object: T, property: string /* keyof T */, value: V, message?: string): void;
763
764 /**
765 * Asserts that object has a property named by property, which can be a string
766 * using dot- and bracket-notation for deep reference.
767 *
768 * @type T Type of object.
769 * @type V Type of value.
770 * @param object Container object.
771 * @param property Potential contained property of object.
772 * @param value Potential expected property value.
773 * @param message Message to display on error.
774 */
775 deepPropertyVal<T, V>(object: T, property: string, value: V, message?: string): void;
776
777 /**
778 * Asserts that object does not have a property named by property, which can be a
779 * string using dot- and bracket-notation for deep reference.
780 *
781 * @type T Type of object.
782 * @type V Type of value.
783 * @param object Container object.
784 * @param property Potential contained property of object.
785 * @param value Potential expected property value.
786 * @param message Message to display on error.
787 */
788 deepPropertyNotVal<T, V>(object: T, property: string, value: T, message?: string): void;
789
790 /**
791 * Asserts that object has a length property with the expected value.
792 *
793 * @type T Type of object.
794 * @param object Container object.
795 * @param length Potential expected length of object.
796 * @param message Message to display on error.
797 */
798 lengthOf<T extends { readonly length?: number }>(object: T, length: number, message?: string): void;
799
800 /**
801 * Asserts that fn will throw an error.
802 *
803 * @param fn Function that may throw.
804 * @param message Message to display on error.
805 */
806 throw(fn: Function, message?: string): void;
807
808 /**
809 * Asserts that function will throw an error with message matching regexp.
810 *
811 * @param fn Function that may throw.
812 * @param regExp Potential expected message match.
813 * @param message Message to display on error.
814 */
815 throw(fn: Function, regExp: RegExp): void;
816
817 /**
818 * Asserts that function will throw an error that is an instance of constructor.
819 *
820 * @param fn Function that may throw.
821 * @param constructor Potential expected error constructor.
822 * @param message Message to display on error.
823 */
824 throw(fn: Function, constructor: Function, message?: string): void;
825
826 /**
827 * Asserts that function will throw an error that is an instance of constructor
828 * and an error with message matching regexp.
829 *
830 * @param fn Function that may throw.
831 * @param constructor Potential expected error constructor.
832 * @param message Message to display on error.
833 */
834 throw(fn: Function, constructor: Function, regExp: RegExp): void;
835
836 /**
837 * Asserts that fn will throw an error.
838 *
839 * @param fn Function that may throw.
840 * @param message Message to display on error.
841 */
842 throws(fn: Function, message?: string): void;
843
844 /**
845 * Asserts that function will throw an error with message matching regexp.
846 *
847 * @param fn Function that may throw.
848 * @param regExp Potential expected message match.
849 * @param message Message to display on error.
850 */
851 throws(fn: Function, regExp: RegExp): void;
852
853 /**
854 * Asserts that function will throw an error that is an instance of constructor.
855 *
856 * @param fn Function that may throw.
857 * @param constructor Potential expected error constructor.
858 * @param message Message to display on error.
859 */
860 throws(fn: Function, errType: Function, message?: string): void;
861
862 /**
863 * Asserts that function will throw an error that is an instance of constructor
864 * and an error with message matching regexp.
865 *
866 * @param fn Function that may throw.
867 * @param constructor Potential expected error constructor.
868 * @param message Message to display on error.
869 */
870 throws(fn: Function, errType: Function, regExp: RegExp): void;
871
872 /**
873 * Asserts that fn will throw an error.
874 *
875 * @param fn Function that may throw.
876 * @param message Message to display on error.
877 */
878 Throw(fn: Function, message?: string): void;
879
880 /**
881 * Asserts that function will throw an error with message matching regexp.
882 *
883 * @param fn Function that may throw.
884 * @param regExp Potential expected message match.
885 * @param message Message to display on error.
886 */
887 Throw(fn: Function, regExp: RegExp): void;
888
889 /**
890 * Asserts that function will throw an error that is an instance of constructor.
891 *
892 * @param fn Function that may throw.
893 * @param constructor Potential expected error constructor.
894 * @param message Message to display on error.
895 */
896 Throw(fn: Function, errType: Function, message?: string): void;
897
898 /**
899 * Asserts that function will throw an error that is an instance of constructor
900 * and an error with message matching regexp.
901 *
902 * @param fn Function that may throw.
903 * @param constructor Potential expected error constructor.
904 * @param message Message to display on error.
905 */
906 Throw(fn: Function, errType: Function, regExp: RegExp): void;
907
908 /**
909 * Asserts that fn will not throw an error.
910 *
911 * @param fn Function that may throw.
912 * @param message Message to display on error.
913 */
914 doesNotThrow(fn: Function, message?: string): void;
915
916 /**
917 * Asserts that function will throw an error with message matching regexp.
918 *
919 * @param fn Function that may throw.
920 * @param regExp Potential expected message match.
921 * @param message Message to display on error.
922 */
923 doesNotThrow(fn: Function, regExp: RegExp): void;
924
925 /**
926 * Asserts that function will throw an error that is an instance of constructor.
927 *
928 * @param fn Function that may throw.
929 * @param constructor Potential expected error constructor.
930 * @param message Message to display on error.
931 */
932 doesNotThrow(fn: Function, errType: Function, message?: string): void;
933
934 /**
935 * Asserts that function will throw an error that is an instance of constructor
936 * and an error with message matching regexp.
937 *
938 * @param fn Function that may throw.
939 * @param constructor Potential expected error constructor.
940 * @param message Message to display on error.
941 */
942 doesNotThrow(fn: Function, errType: Function, regExp: RegExp): void;
943
944 /**
945 * Compares two values using operator.
946 *
947 * @param val1 Left value during comparison.
948 * @param operator Comparison operator.
949 * @param val2 Right value during comparison.
950 * @param message Message to display on error.
951 */
952 operator(val1: OperatorComparable, operator: Operator, val2: OperatorComparable, message?: string): void;
953
954 /**
955 * Asserts that the target is equal to expected, to within a +/- delta range.
956 *
957 * @param actual Actual value
958 * @param expected Potential expected value.
959 * @param delta Maximum differenced between values.
960 * @param message Message to display on error.
961 */
962 closeTo(actual: number, expected: number, delta: number, message?: string): void;
963
964 /**
965 * Asserts that the target is equal to expected, to within a +/- delta range.
966 *
967 * @param actual Actual value
968 * @param expected Potential expected value.
969 * @param delta Maximum differenced between values.
970 * @param message Message to display on error.
971 */
972 approximately(act: number, exp: number, delta: number, message?: string): void;
973
974 /**
975 * Asserts that set1 and set2 have the same members. Order is not take into account.
976 *
977 * @type T Type of set values.
978 * @param set1 Actual set of values.
979 * @param set2 Potential expected set of values.
980 * @param message Message to display on error.
981 */
982 sameMembers<T>(set1: T[], set2: T[], message?: string): void;
983
984 /**
985 * Asserts that set1 and set2 have the same members using deep equality checking.
986 * Order is not take into account.
987 *
988 * @type T Type of set values.
989 * @param set1 Actual set of values.
990 * @param set2 Potential expected set of values.
991 * @param message Message to display on error.
992 */
993 sameDeepMembers<T>(set1: T[], set2: T[], message?: string): void;
994
995 /**
996 * Asserts that subset is included in superset. Order is not take into account.
997 *
998 * @type T Type of set values.
999 * @param superset Actual set of values.
1000 * @param subset Potential contained set of values.
1001 * @param message Message to display on error.
1002 */
1003 includeMembers<T>(superset: T[], subset: T[], message?: string): void;
1004
1005 /**
1006 * Asserts that subset is included in superset using deep equality checking.
1007 * Order is not take into account.
1008 *
1009 * @type T Type of set values.
1010 * @param superset Actual set of values.
1011 * @param subset Potential contained set of values.
1012 * @param message Message to display on error.
1013 */
1014 includeDeepMembers<T>(superset: T[], subset: T[], message?: string): void;
1015
1016 /**
1017 * Asserts that non-object, non-array value inList appears in the flat array list.
1018 *
1019 * @type T Type of list values.
1020 * @param inList Value expected to be in the list.
1021 * @param list List of values.
1022 * @param message Message to display on error.
1023 */
1024 oneOf<T>(inList: T, list: T[], message?: string): void;
1025
1026 /**
1027 * Asserts that a function changes the value of a property.
1028 *
1029 * @type T Type of object.
1030 * @param modifier Function to run.
1031 * @param object Container object.
1032 * @param property Property of object expected to be modified.
1033 * @param message Message to display on error.
1034 */
1035 changes<T>(modifier: Function, object: T, property: string /* keyof T */, message?: string): void
1036
1037 /**
1038 * Asserts that a function does not change the value of a property.
1039 *
1040 * @type T Type of object.
1041 * @param modifier Function to run.
1042 * @param object Container object.
1043 * @param property Property of object expected not to be modified.
1044 * @param message Message to display on error.
1045 */
1046 doesNotChange<T>(modifier: Function, object: T, property: string /* keyof T */, message?: string): void
1047
1048 /**
1049 * Asserts that a function increases an object property.
1050 *
1051 * @type T Type of object.
1052 * @param modifier Function to run.
1053 * @param object Container object.
1054 * @param property Property of object expected to be increased.
1055 * @param message Message to display on error.
1056 */
1057 increases<T>(modifier: Function, object: T, property: string /* keyof T */, message?: string): void
1058
1059 /**
1060 * Asserts that a function does not increase an object property.
1061 *
1062 * @type T Type of object.
1063 * @param modifier Function to run.
1064 * @param object Container object.
1065 * @param property Property of object expected not to be increased.
1066 * @param message Message to display on error.
1067 */
1068 doesNotIncrease<T>(modifier: Function, object: T, property: string /* keyof T */, message?: string): void
1069
1070 /**
1071 * Asserts that a function decreases an object property.
1072 *
1073 * @type T Type of object.
1074 * @param modifier Function to run.
1075 * @param object Container object.
1076 * @param property Property of object expected to be decreased.
1077 * @param message Message to display on error.
1078 */
1079 decreases<T>(modifier: Function, object: T, property: string /* keyof T */, message?: string): void
1080
1081 /**
1082 * Asserts that a function does not decrease an object property.
1083 *
1084 * @type T Type of object.
1085 * @param modifier Function to run.
1086 * @param object Container object.
1087 * @param property Property of object expected not to be decreased.
1088 * @param message Message to display on error.
1089 */
1090 doesNotDecrease<T>(modifier: Function, object: T, property: string /* keyof T */, message?: string): void
1091
1092 /**
1093 * Asserts if value is not a false value, and throws if it is a true value.
1094 *
1095 * @type T Type of object.
1096 * @param object Actual value.
1097 * @param message Message to display on error.
1098 * @remarks This is added to allow for chai to be a drop-in replacement for
1099 * Node’s assert class.
1100 */
1101 ifError<T>(object: T, message?: string): void;
1102
1103 /**
1104 * Asserts that object is extensible (can have new properties added to it).
1105 *
1106 * @type T Type of object
1107 * @param object Actual value.
1108 * @param message Message to display on error.
1109 */
1110 isExtensible<T>(object: T, message?: string): void;
1111
1112 /**
1113 * Asserts that object is extensible (can have new properties added to it).
1114 *
1115 * @type T Type of object
1116 * @param object Actual value.
1117 * @param message Message to display on error.
1118 */
1119 extensible<T>(object: T, message?: string): void;
1120
1121 /**
1122 * Asserts that object is not extensible.
1123 *
1124 * @type T Type of object
1125 * @param object Actual value.
1126 * @param message Message to display on error.
1127 */
1128 isNotExtensible<T>(object: T, message?: string): void;
1129
1130 /**
1131 * Asserts that object is not extensible.
1132 *
1133 * @type T Type of object
1134 * @param object Actual value.
1135 * @param message Message to display on error.
1136 */
1137 notExtensible<T>(object: T, message?: string): void;
1138
1139 /**
1140 * Asserts that object is sealed (can have new properties added to it
1141 * and its existing properties cannot be removed).
1142 *
1143 * @type T Type of object
1144 * @param object Actual value.
1145 * @param message Message to display on error.
1146 */
1147 isSealed<T>(object: T, message?: string): void;
1148
1149 /**
1150 * Asserts that object is sealed (can have new properties added to it
1151 * and its existing properties cannot be removed).
1152 *
1153 * @type T Type of object
1154 * @param object Actual value.
1155 * @param message Message to display on error.
1156 */
1157 sealed<T>(object: T, message?: string): void;
1158
1159 /**
1160 * Asserts that object is not sealed.
1161 *
1162 * @type T Type of object
1163 * @param object Actual value.
1164 * @param message Message to display on error.
1165 */
1166 isNotSealed<T>(object: T, message?: string): void;
1167
1168 /**
1169 * Asserts that object is not sealed.
1170 *
1171 * @type T Type of object
1172 * @param object Actual value.
1173 * @param message Message to display on error.
1174 */
1175 notSealed<T>(object: T, message?: string): void;
1176
1177 /**
1178 * Asserts that object is frozen (cannot have new properties added to it
1179 * and its existing properties cannot be removed).
1180 *
1181 * @type T Type of object
1182 * @param object Actual value.
1183 * @param message Message to display on error.
1184 */
1185 isFrozen<T>(object: T, message?: string): void;
1186
1187 /**
1188 * Asserts that object is frozen (cannot have new properties added to it
1189 * and its existing properties cannot be removed).
1190 *
1191 * @type T Type of object
1192 * @param object Actual value.
1193 * @param message Message to display on error.
1194 */
1195 frozen<T>(object: T, message?: string): void;
1196
1197 /**
1198 * Asserts that object is not frozen (cannot have new properties added to it
1199 * and its existing properties cannot be removed).
1200 *
1201 * @type T Type of object
1202 * @param object Actual value.
1203 * @param message Message to display on error.
1204 */
1205 isNotFrozen<T>(object: T, message?: string): void;
1206
1207 /**
1208 * Asserts that object is not frozen (cannot have new properties added to it
1209 * and its existing properties cannot be removed).
1210 *
1211 * @type T Type of object
1212 * @param object Actual value.
1213 * @param message Message to display on error.
1214 */
1215 notFrozen<T>(object: T, message?: string): void;
1216 }
1217
1218 export interface Config {
1219 /**
1220 * Default: false
1221 */
1222 includeStack: boolean;
1223
1224 /**
1225 * Default: true
1226 */
1227 showDiff: boolean;
1228
1229 /**
1230 * Default: 40
1231 */
1232 truncateThreshold: number;
1233 }
1234
1235 export class AssertionError {
1236 constructor(message: string, _props?: any, ssf?: Function);
1237 name: string;
1238 message: string;
1239 showDiff: boolean;
1240 stack: string;
1241 }
1242}
1243
1244declare const chai: Chai.ChaiStatic;
1245
1246declare module "chai" {
1247 export = chai;
1248}
1249
1250interface Object {
1251 should: Chai.Assertion;
1252}