UNPKG

2.48 kBTypeScriptView Raw
1// Type definitions for commonjs-assert 1.5
2// Project: https://github.com/browserify/commonjs-assert, https://github.com/defunctzombie/commonjs-assert
3// Definitions by: Nico Gallinal <https://github.com/nicoabie>
4// Linus Unnebäck <https://github.com/LinusU>
5// ExE Boss <https://github.com/ExE-Boss>
6// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
7
8declare function assert(value: any, message?: string): asserts value;
9
10declare namespace assert {
11 function fail(actual?: any, expected?: any, message?: string, operator?: string): never;
12
13 function ok(value: any, message?: string): asserts value;
14
15 /** @deprecated Use `strictEqual` instead */
16 function equal(actual: any, expected: any, message?: string): void;
17
18 /** @deprecated Use `notStrictEqual` instead */
19 function notEqual(actual: any, expected: any, message?: string): void;
20
21 /** @deprecated Use `deepStrictEqual` instead */
22 function deepEqual(actual: any, expected: any, message?: string): void;
23
24 /** @deprecated Use `notDeepStrictEqual` instead */
25 function notDeepEqual(actual: any, expected: any, message?: string): void;
26
27 function deepStrictEqual<T>(actual: any, expected: T, message?: string): asserts actual is T;
28
29 function notDeepStrictEqual(actual: any, expected: any, message?: string): void;
30
31 function strictEqual<T>(actual: any, expected: T, message?: string): asserts actual is T;
32
33 function notStrictEqual(actual: any, expected: any, message?: string): void;
34
35 function throws(block: () => void, message?: string): void;
36 function throws(block: () => void, error: (() => void) | ((err: any) => boolean) | RegExp, message?: string): void;
37
38 function doesNotThrow(block: () => void, message?: string): void;
39 function doesNotThrow(
40 block: () => void,
41 error: (() => void) | ((err: any) => boolean) | RegExp,
42 message?: string,
43 ): void;
44
45 function ifError(value: any): asserts value is null | undefined;
46
47 class AssertionError implements Error {
48 name: string;
49 message: string;
50 actual: any;
51 expected: any;
52 operator: string;
53 generatedMessage: boolean;
54
55 constructor(options?: {
56 message?: string;
57 actual?: any;
58 expected?: any;
59 operator?: string;
60 stackStartFunction?: () => void;
61 });
62 }
63
64 const strict: typeof assert;
65}
66
67export = assert;