-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassert.test.ts
More file actions
36 lines (32 loc) · 988 Bytes
/
Copy pathassert.test.ts
File metadata and controls
36 lines (32 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { test } from 'node:test';
import { deepStrictEqual, fail, ok, strictEqual, throws } from 'node:assert/strict';
export { deepStrictEqual as equals, ok as assert, strictEqual as strict, test, throws };
export const exists = (value: unknown): void => {
ok(value !== null && typeof value !== 'undefined');
};
export const matches = (
actual: object,
expected: Record<PropertyKey, unknown>,
): void => {
for (const key of Reflect.ownKeys(expected)) {
deepStrictEqual((actual as Record<PropertyKey, unknown>)[key], expected[key]);
}
};
export const throwsAsync = async (
fn: () => unknown,
ErrorClass?: new (...args: any[]) => Error,
messageIncludes?: string,
): Promise<void> => {
try {
await fn();
} catch (error) {
if (ErrorClass) {
ok(error instanceof ErrorClass);
}
if (messageIncludes) {
ok(error instanceof Error && error.message.includes(messageIncludes));
}
return;
}
fail('Expected function to reject.');
};