1 | // Type definitions for assert-plus 1.0
|
2 | // Project: https://github.com/mcavage/node-assert-plus#readme
|
3 | // Definitions by: Костя Третяк <https://github.com/KostyaTretyak>
|
4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
5 |
|
6 | /// <reference types="node" />
|
7 |
|
8 | import { Stream } from 'stream';
|
9 |
|
10 | export function array(arr: any[], message ?: string): void;
|
11 |
|
12 | export function bool(bool: boolean, message ?: string): void;
|
13 |
|
14 | export function buffer(buffer: Buffer, message ?: string): void;
|
15 |
|
16 | export function func(func: any, message ?: string): void;
|
17 |
|
18 | export function number(number: number, message ?: string): void;
|
19 |
|
20 | export function finite(finite: number, message ?: string): void;
|
21 |
|
22 | export function object(obj: any, message ?: string): void;
|
23 |
|
24 | export function string(str: string, message ?: string): void;
|
25 |
|
26 | export function stream(stream: Stream, message ?: string): void;
|
27 |
|
28 | export function date(date: Date, message ?: string): void;
|
29 |
|
30 | export function regexp(regexp: RegExp, message ?: string): void;
|
31 |
|
32 | export function uuid(uuid: string, message ?: string): void;
|
33 |
|
34 | export function arrayOfArray(arr: any[][], message ?: string): void;
|
35 |
|
36 | export function arrayOfBool(arr: boolean[], message ?: string): void;
|
37 |
|
38 | export function arrayOfBuffer(arr: Buffer[], message ?: string): void;
|
39 |
|
40 | export function arrayOfFunc(arr: any[], message ?: string): void;
|
41 |
|
42 | export function arrayOfNumber(arr: number[], message ?: string): void;
|
43 |
|
44 | export function arrayOfFinite(arr: number[], message ?: string): void;
|
45 |
|
46 | export function arrayOfObject(arr: any[], message ?: string): void;
|
47 |
|
48 | export function arrayOfString(arr: string[], message ?: string): void;
|
49 |
|
50 | export function arrayOfStream(arr: Stream[], message ?: string): void;
|
51 |
|
52 | export function arrayOfDate(arr: Date[], message ?: string): void;
|
53 |
|
54 | export function arrayOfRegexp(arr: RegExp[], message ?: string): void;
|
55 |
|
56 | export function arrayOfUuid(arr: string[], message ?: string): void;
|
57 |
|
58 | export function optionalArray(arr: any[] | undefined, message ?: string): void;
|
59 |
|
60 | export function optionalBool(bool: boolean | undefined, message ?: string): void;
|
61 |
|
62 | export function optionalBuffer(buffer: Buffer | undefined, message ?: string): void;
|
63 |
|
64 | export function optionalFunc(options: any, message ?: string): void;
|
65 |
|
66 | export function optionalNumber(options: number | undefined, message ?: string): void;
|
67 |
|
68 | export function optionalFinite(options: number | undefined, message ?: string): void;
|
69 |
|
70 | export function optionalObject(options: any, message ?: string): void;
|
71 |
|
72 | export function optionalString(options: string | undefined, message ?: string): void;
|
73 |
|
74 | export function optionalStream(options: Stream | undefined, message ?: string): void;
|
75 |
|
76 | export function optionalDate(options: Date | undefined, message ?: string): void;
|
77 |
|
78 | export function optionalRegexp(options: RegExp | undefined, message ?: string): void;
|
79 |
|
80 | export function optionalUuid(options: string | undefined, message ?: string): void;
|
81 |
|
82 | export function optionalArrayOfArray(arr: any[][] | undefined, message ?: string): void;
|
83 |
|
84 | export function optionalArrayOfBool(arr: boolean[] | undefined, message ?: string): void;
|
85 |
|
86 | export function optionalArrayOfBuffer(arr: Buffer[] | undefined, message ?: string): void;
|
87 |
|
88 | export function optionalArrayOfFunc(arr: any[] | undefined, message ?: string): void;
|
89 |
|
90 | export function optionalArrayOfNumber(arr: number[] | undefined, message ?: string): void;
|
91 |
|
92 | export function optionalArrayOfFinite(arr: number[] | undefined, message ?: string): void;
|
93 |
|
94 | export function optionalArrayOfObject(arr: any[] | undefined, message ?: string): void;
|
95 |
|
96 | export function optionalArrayOfString(arr: string[] | undefined, message ?: string): void;
|
97 |
|
98 | export function optionalArrayOfStream(arr: Stream[] | undefined, message ?: string): void;
|
99 |
|
100 | export function optionalArrayOfDate(arr: Date[] | undefined, message ?: string): void;
|
101 |
|
102 | export function optionalArrayOfRegexp(arr: RegExp[] | undefined, message ?: string): void;
|
103 |
|
104 | export function optionalArrayOfUuid(arr: string[] | undefined, message ?: string): void;
|
105 |
|
106 | export function AssertionError(options: any, message ?: string): void;
|
107 |
|
108 | /**
|
109 | * Throws an `AssertionError`. If `message` is falsy, the error message is set
|
110 | * as the values of `actual` and `expected` separated by the provided `operator`.
|
111 | * Otherwise, the error message is the value of `message`.
|
112 | *
|
113 | * ```js
|
114 | * const assert = require('assert');
|
115 | *
|
116 | * assert.fail(1, 2, undefined, '>');
|
117 | * // AssertionError: 1 > 2
|
118 | *
|
119 | * assert.fail(1, 2, 'whoops', '>');
|
120 | * // AssertionError: whoops
|
121 | * ```
|
122 | */
|
123 | export function fail(actual: any, expected: any, message: any, operator: any): void;
|
124 |
|
125 | /**
|
126 | * Tests if `value` is truthy. It is equivalent to `assert.equal(!!value, true, message)`.
|
127 | *
|
128 | * If `value` is not truthy, an `AssertionError` is thrown with a `message` property
|
129 | * set equal to the value of the `message` parameter.
|
130 | * If the `message` parameter is `undefined`, a default error message is assigned.
|
131 | *
|
132 | * ```js
|
133 | * const assert = require('assert');
|
134 | *
|
135 | * assert.ok(true);
|
136 | * // OK
|
137 | * assert.ok(1);
|
138 | * // OK
|
139 | * assert.ok(false);
|
140 | * // throws "AssertionError: false == true"
|
141 | * assert.ok(0);
|
142 | * // throws "AssertionError: 0 == true"
|
143 | * assert.ok(false, 'it\'s false');
|
144 | * // throws "AssertionError: it's false"
|
145 | * ```
|
146 | */
|
147 | export function ok(options: any, message ?: string): void;
|
148 |
|
149 | /**
|
150 | * Tests shallow, coercive equality between the actual and expected parameters
|
151 | * using the equal comparison operator ( `==` ).
|
152 | *
|
153 | * ```js
|
154 | * const assert = require('assert');
|
155 | *
|
156 | * assert.equal(1, 1);
|
157 | * // OK, 1 == 1
|
158 | * assert.equal(1, '1');
|
159 | * // OK, 1 == '1'
|
160 | *
|
161 | * assert.equal(1, 2);
|
162 | * // AssertionError: 1 == 2
|
163 | * assert.equal({a: {b: 1}}, {a: {b: 1}});
|
164 | * //AssertionError: { a: { b: 1 } } == { a: { b: 1 } }
|
165 | * ```
|
166 | *
|
167 | * If the values are not equal, an `AssertionError` is thrown with
|
168 | * a `message` property set equal to the value of the `message` parameter.
|
169 | * If the `message` parameter is undefined, a default error message is assigned.
|
170 | */
|
171 | export function equal(actual: any, expected: any, message ?: string): void;
|
172 |
|
173 | /**
|
174 | * Tests shallow, coercive inequality with the not equal comparison operator ( `!=` ).
|
175 | *
|
176 | * ```js
|
177 | * const assert = require('assert');
|
178 | *
|
179 | * assert.notEqual(1, 2);
|
180 | * // OK
|
181 | *
|
182 | * assert.notEqual(1, 1);
|
183 | * // AssertionError: 1 != 1
|
184 | *
|
185 | * assert.notEqual(1, '1');
|
186 | * // AssertionError: 1 != '1'
|
187 | * ```
|
188 | *
|
189 | * If the values are equal, an `AssertionError` is thrown with
|
190 | * a `message` property set equal to the value of the `message` parameter.
|
191 | * If the `message` parameter is undefined, a default error message is assigned.
|
192 | */
|
193 | export function notEqual(actual: any, expected: any, message ?: string): void;
|
194 |
|
195 | /**
|
196 | * Tests for deep equality between the `actual` and `expected` parameters.
|
197 | * Primitive values are compared with the equal comparison operator ( `==` ).
|
198 | *
|
199 | * Only enumerable "own" properties are considered.
|
200 | * The `deepEqual()` implementation does not test object prototypes, attached symbols,
|
201 | * or non-enumerable properties. This can lead to some potentially surprising results.
|
202 | * For example, the following example does not throw an `AssertionError` because
|
203 | * the properties on the Error object are non-enumerable:
|
204 | *
|
205 | * ```js
|
206 | * // WARNING: This does not throw an AssertionError!
|
207 | * assert.deepEqual(Error('a'), Error('b'));
|
208 | * ```
|
209 | *
|
210 | * "Deep" equality means that the enumerable "own" properties of child objects are evaluated also.
|
211 | *
|
212 | * If the values are not equal, an `AssertionError` is thrown with a `message` property
|
213 | * set equal to the value of the `message` parameter. If the `message` parameter is undefined,
|
214 | * a default error message is assigned.
|
215 | */
|
216 | export function deepEqual<T>(actual: T, expected: T, message ?: string): void;
|
217 |
|
218 | /**
|
219 | * Tests for any deep inequality. Opposite of `assert.deepEqual()`.
|
220 | *
|
221 | * ```js
|
222 | * const assert = require('assert');
|
223 | *
|
224 | * const obj1 = { a : { b : 1 } };
|
225 | * const obj2 = { a : { b : 2 } };
|
226 | * const obj3 = { a : { b : 1 } };
|
227 | * const obj4 = Object.create(obj1);
|
228 | *
|
229 | * assert.notDeepEqual(obj1, obj1);
|
230 | * // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
|
231 | *
|
232 | * assert.notDeepEqual(obj1, obj2);
|
233 | * // OK, obj1 and obj2 are not deeply equal
|
234 | *
|
235 | * assert.notDeepEqual(obj1, obj3);
|
236 | * // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
|
237 | *
|
238 | * assert.notDeepEqual(obj1, obj4);
|
239 | * // OK, obj1 and obj2 are not deeply equal
|
240 | * ```
|
241 | *
|
242 | * If the values are deeply equal, an `AssertionError` is thrown with
|
243 | * a `message` property set equal to the value of the `message` parameter.
|
244 | * If the `message` parameter is undefined, a default error message is assigned.
|
245 | */
|
246 | export function notDeepEqual(actual: any, expected: any, message ?: string): void;
|
247 |
|
248 | /**
|
249 | * Tests strict equality as determined by the strict equality operator ( `===` ).
|
250 | *
|
251 | * ```js
|
252 | * const assert = require('assert');
|
253 | *
|
254 | * assert.strictEqual(1, 2);
|
255 | * // AssertionError: 1 === 2
|
256 | *
|
257 | * assert.strictEqual(1, 1);
|
258 | * // OK
|
259 | *
|
260 | * assert.strictEqual(1, '1');
|
261 | * // AssertionError: 1 === '1'
|
262 | * ```
|
263 | *
|
264 | * If the values are not strictly equal, an `AssertionError` is thrown with
|
265 | * a `message` property set equal to the value of the `message` parameter.
|
266 | * If the `message` parameter is undefined, a default error message is assigned.
|
267 | */
|
268 | export function strictEqual<T>(actual: T, expected: T, message ?: string): void;
|
269 |
|
270 | /**
|
271 | * Tests strict inequality as determined by the strict not equal operator ( `!==` ).
|
272 | *
|
273 | * ```js
|
274 | * const assert = require('assert');
|
275 | *
|
276 | * assert.notStrictEqual(1, 2);
|
277 | * // OK
|
278 | *
|
279 | * assert.notStrictEqual(1, 1);
|
280 | * // AssertionError: 1 !== 1
|
281 | *
|
282 | * assert.notStrictEqual(1, '1');
|
283 | * // OK
|
284 | * ```
|
285 | *
|
286 | * If the values are strictly equal, an `AssertionError` is thrown with a `message` property
|
287 | * set equal to the value of the `message` parameter. If the `message` parameter is undefined,
|
288 | * a default error message is assigned.
|
289 | */
|
290 | export function notStrictEqual(actual: any, expected: any, message ?: string): void;
|
291 |
|
292 | export function throws(block: any, error ?: any, message ?: string): void;
|
293 |
|
294 | /**
|
295 | * Asserts that the function `block` does not throw an error. See `assert.throws()` for more details.
|
296 | *
|
297 | * When `assert.doesNotThrow()` is called, it will immediately call the `block` function.
|
298 | *
|
299 | * If an error is thrown and it is the same type as that specified by the `error` parameter,
|
300 | * then an `AssertionError` is thrown. If the error is of a different type,
|
301 | * or if the `error` parameter is undefined, the error is propagated back to the caller.
|
302 | *
|
303 | * The following, for instance, will throw the TypeError because there is no matching error type in the assertion:
|
304 | * ```js
|
305 | * assert.doesNotThrow(
|
306 | * () => {
|
307 | * throw new TypeError('Wrong value');
|
308 | * },
|
309 | * SyntaxError
|
310 | * );
|
311 | * ```
|
312 | *
|
313 | * However, the following will result in an `AssertionError` with the message 'Got unwanted exception (TypeError)..':
|
314 | * ```js
|
315 | * assert.doesNotThrow(
|
316 | * () => {
|
317 | * throw new TypeError('Wrong value');
|
318 | * },
|
319 | * TypeError
|
320 | * );
|
321 | * ```
|
322 | *
|
323 | * If an `AssertionError` is thrown and a value is provided for the `message` parameter,
|
324 | * the value of `message` will be appended to the `AssertionError` message:
|
325 | * ```js
|
326 | * assert.doesNotThrow(
|
327 | * () => {
|
328 | * throw new TypeError('Wrong value');
|
329 | * },
|
330 | * TypeError,
|
331 | * 'Whoops'
|
332 | * );
|
333 | * // Throws: AssertionError: Got unwanted exception (TypeError). Whoops
|
334 | * ```
|
335 | */
|
336 | export function doesNotThrow(block: any, error ?: any, message ?: string): void;
|
337 |
|
338 | /**
|
339 | * Throws `value` if `value` is truthy. This is useful when testing the `error` argument in callbacks.
|
340 | * ```js
|
341 | * const assert = require('assert');
|
342 | *
|
343 | * assert.ifError(0);
|
344 | * // OK
|
345 | * assert.ifError(1);
|
346 | * // Throws 1
|
347 | * assert.ifError('error');
|
348 | * // Throws 'error'
|
349 | * assert.ifError(new Error());
|
350 | * // Throws Error
|
351 | * ```
|
352 | */
|
353 | export function ifError(value: any): void;
|
354 |
|
355 | export as namespace AssertPlus;
|