1 | declare 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 | undefined;
|
---|
15 | actual?: any;
|
---|
16 | expected?: any;
|
---|
17 | operator?: string | undefined;
|
---|
18 | // tslint:disable-next-line:ban-types
|
---|
19 | stackStartFn?: Function | undefined;
|
---|
20 | });
|
---|
21 | }
|
---|
22 |
|
---|
23 | class CallTracker {
|
---|
24 | calls(exact?: number): () => void;
|
---|
25 | calls<Func extends (...args: any[]) => any>(fn?: Func, exact?: number): Func;
|
---|
26 | report(): CallTrackerReportInformation[];
|
---|
27 | verify(): void;
|
---|
28 | }
|
---|
29 | interface CallTrackerReportInformation {
|
---|
30 | message: string;
|
---|
31 | /** The actual number of times the function was called. */
|
---|
32 | actual: number;
|
---|
33 | /** The number of times the function was expected to be called. */
|
---|
34 | expected: number;
|
---|
35 | /** The name of the function that is wrapped. */
|
---|
36 | operator: string;
|
---|
37 | /** A stack trace of the function. */
|
---|
38 | stack: object;
|
---|
39 | }
|
---|
40 |
|
---|
41 | type AssertPredicate = RegExp | (new () => object) | ((thrown: any) => boolean) | object | Error;
|
---|
42 |
|
---|
43 | function fail(message?: string | Error): never;
|
---|
44 | /** @deprecated since v10.0.0 - use fail([message]) or other assert functions instead. */
|
---|
45 | function fail(
|
---|
46 | actual: any,
|
---|
47 | expected: any,
|
---|
48 | message?: string | Error,
|
---|
49 | operator?: string,
|
---|
50 | // tslint:disable-next-line:ban-types
|
---|
51 | stackStartFn?: Function,
|
---|
52 | ): never;
|
---|
53 | function ok(value: any, message?: string | Error): asserts value;
|
---|
54 | /** @deprecated since v9.9.0 - use strictEqual() instead. */
|
---|
55 | function equal(actual: any, expected: any, message?: string | Error): void;
|
---|
56 | /** @deprecated since v9.9.0 - use notStrictEqual() instead. */
|
---|
57 | function notEqual(actual: any, expected: any, message?: string | Error): void;
|
---|
58 | /** @deprecated since v9.9.0 - use deepStrictEqual() instead. */
|
---|
59 | function deepEqual(actual: any, expected: any, message?: string | Error): void;
|
---|
60 | /** @deprecated since v9.9.0 - use notDeepStrictEqual() instead. */
|
---|
61 | function notDeepEqual(actual: any, expected: any, message?: string | Error): void;
|
---|
62 | function strictEqual<T>(actual: any, expected: T, message?: string | Error): asserts actual is T;
|
---|
63 | function notStrictEqual(actual: any, expected: any, message?: string | Error): void;
|
---|
64 | function deepStrictEqual<T>(actual: any, expected: T, message?: string | Error): asserts actual is T;
|
---|
65 | function notDeepStrictEqual(actual: any, expected: any, message?: string | Error): void;
|
---|
66 |
|
---|
67 | function throws(block: () => any, message?: string | Error): void;
|
---|
68 | function throws(block: () => any, error: AssertPredicate, message?: string | Error): void;
|
---|
69 | function doesNotThrow(block: () => any, message?: string | Error): void;
|
---|
70 | function doesNotThrow(block: () => any, error: AssertPredicate, message?: string | Error): void;
|
---|
71 |
|
---|
72 | function ifError(value: any): asserts value is null | undefined;
|
---|
73 |
|
---|
74 | function rejects(block: (() => Promise<any>) | Promise<any>, message?: string | Error): Promise<void>;
|
---|
75 | function rejects(
|
---|
76 | block: (() => Promise<any>) | Promise<any>,
|
---|
77 | error: AssertPredicate,
|
---|
78 | message?: string | Error,
|
---|
79 | ): Promise<void>;
|
---|
80 | function doesNotReject(block: (() => Promise<any>) | Promise<any>, message?: string | Error): Promise<void>;
|
---|
81 | function doesNotReject(
|
---|
82 | block: (() => Promise<any>) | Promise<any>,
|
---|
83 | error: AssertPredicate,
|
---|
84 | message?: string | Error,
|
---|
85 | ): Promise<void>;
|
---|
86 |
|
---|
87 | const strict: Omit<
|
---|
88 | typeof assert,
|
---|
89 | | 'equal'
|
---|
90 | | 'notEqual'
|
---|
91 | | 'deepEqual'
|
---|
92 | | 'notDeepEqual'
|
---|
93 | | 'ok'
|
---|
94 | | 'strictEqual'
|
---|
95 | | 'deepStrictEqual'
|
---|
96 | | 'ifError'
|
---|
97 | | 'strict'
|
---|
98 | > & {
|
---|
99 | (value: any, message?: string | Error): asserts value;
|
---|
100 | equal: typeof strictEqual;
|
---|
101 | notEqual: typeof notStrictEqual;
|
---|
102 | deepEqual: typeof deepStrictEqual;
|
---|
103 | notDeepEqual: typeof notDeepStrictEqual;
|
---|
104 |
|
---|
105 | // Mapped types and assertion functions are incompatible?
|
---|
106 | // TS2775: Assertions require every name in the call target
|
---|
107 | // to be declared with an explicit type annotation.
|
---|
108 | ok: typeof ok;
|
---|
109 | strictEqual: typeof strictEqual;
|
---|
110 | deepStrictEqual: typeof deepStrictEqual;
|
---|
111 | ifError: typeof ifError;
|
---|
112 | strict: typeof strict;
|
---|
113 | };
|
---|
114 | }
|
---|
115 |
|
---|
116 | export = assert;
|
---|
117 | }
|
---|