UNPKG

4.33 kBTypeScriptView Raw
1declare module 'assert' {
2 function assert(value: any, message?: string | Error): asserts value;
3 namespace assert {
4 class AssertionError implements Error {
5 name: string;
6 message: string;
7 actual: any;
8 expected: any;
9 operator: string;
10 generatedMessage: boolean;
11 code: 'ERR_ASSERTION';
12
13 constructor(options?: {
14 message?: string;
15 actual?: any;
16 expected?: any;
17 operator?: string;
18 // tslint:disable-next-line:ban-types
19 stackStartFn?: Function;
20 });
21 }
22
23 type AssertPredicate = RegExp | (new () => object) | ((thrown: any) => boolean) | object | Error;
24
25 function fail(message?: string | Error): never;
26 /** @deprecated since v10.0.0 - use fail([message]) or other assert functions instead. */
27 function fail(
28 actual: any,
29 expected: any,
30 message?: string | Error,
31 operator?: string,
32 // tslint:disable-next-line:ban-types
33 stackStartFn?: Function,
34 ): never;
35 function ok(value: any, message?: string | Error): asserts value;
36 /** @deprecated since v9.9.0 - use strictEqual() instead. */
37 function equal(actual: any, expected: any, message?: string | Error): void;
38 /** @deprecated since v9.9.0 - use notStrictEqual() instead. */
39 function notEqual(actual: any, expected: any, message?: string | Error): void;
40 /** @deprecated since v9.9.0 - use deepStrictEqual() instead. */
41 function deepEqual(actual: any, expected: any, message?: string | Error): void;
42 /** @deprecated since v9.9.0 - use notDeepStrictEqual() instead. */
43 function notDeepEqual(actual: any, expected: any, message?: string | Error): void;
44 function strictEqual<T>(actual: any, expected: T, message?: string | Error): asserts actual is T;
45 function notStrictEqual(actual: any, expected: any, message?: string | Error): void;
46 function deepStrictEqual<T>(actual: any, expected: T, message?: string | Error): asserts actual is T;
47 function notDeepStrictEqual(actual: any, expected: any, message?: string | Error): void;
48
49 function throws(block: () => any, message?: string | Error): void;
50 function throws(block: () => any, error: AssertPredicate, message?: string | Error): void;
51 function doesNotThrow(block: () => any, message?: string | Error): void;
52 function doesNotThrow(block: () => any, error: AssertPredicate, message?: string | Error): void;
53
54 function ifError(value: any): asserts value is null | undefined;
55
56 function rejects(block: (() => Promise<any>) | Promise<any>, message?: string | Error): Promise<void>;
57 function rejects(
58 block: (() => Promise<any>) | Promise<any>,
59 error: AssertPredicate,
60 message?: string | Error,
61 ): Promise<void>;
62 function doesNotReject(block: (() => Promise<any>) | Promise<any>, message?: string | Error): Promise<void>;
63 function doesNotReject(
64 block: (() => Promise<any>) | Promise<any>,
65 error: AssertPredicate,
66 message?: string | Error,
67 ): Promise<void>;
68
69 const strict: Omit<
70 typeof assert,
71 | 'equal'
72 | 'notEqual'
73 | 'deepEqual'
74 | 'notDeepEqual'
75 | 'ok'
76 | 'strictEqual'
77 | 'deepStrictEqual'
78 | 'ifError'
79 | 'strict'
80 > & {
81 (value: any, message?: string | Error): asserts value;
82 equal: typeof strictEqual;
83 notEqual: typeof notStrictEqual;
84 deepEqual: typeof deepStrictEqual;
85 notDeepEqual: typeof notDeepStrictEqual;
86
87 // Mapped types and assertion functions are incompatible?
88 // TS2775: Assertions require every name in the call target
89 // to be declared with an explicit type annotation.
90 ok: typeof ok;
91 strictEqual: typeof strictEqual;
92 deepStrictEqual: typeof deepStrictEqual;
93 ifError: typeof ifError;
94 strict: typeof strict;
95 };
96 }
97
98 export = assert;
99}