-
Notifications
You must be signed in to change notification settings - Fork 4
/
_assertions_test.ts
39 lines (36 loc) · 1.48 KB
/
_assertions_test.ts
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
37
38
39
import { assertExpectError, assertInstanceOf } from "./_assertions.ts";
import { AssertionError, assertThrows } from "./dev_deps.ts";
class CustomError extends Error {
constructor(message?: string) {
super(message);
this.name = "CustomError";
Object.setPrototypeOf(this, CustomError.prototype);
}
}
Deno.test({
name: "assertInstanceOf",
fn() {
assertInstanceOf(new Date(), Date);
assertInstanceOf(new Error(), Error);
assertThrows(() => assertInstanceOf(null, Date), AssertionError);
assertThrows(() => assertInstanceOf(undefined, Date), AssertionError);
assertThrows(() => assertInstanceOf(Date, Date), AssertionError);
assertThrows(() => assertInstanceOf(Error, Error), AssertionError);
assertThrows(() => assertInstanceOf(new Date(), Error), AssertionError);
},
});
Deno.test({
name: "assertExpectError",
fn() {
assertExpectError(new Error());
assertExpectError(new Error(), Error);
assertExpectError(new CustomError(), Error);
assertExpectError(new CustomError(), CustomError);
assertThrows(() => assertExpectError(null, Date), AssertionError);
assertThrows(() => assertExpectError(undefined, Date), AssertionError);
assertThrows(() => assertExpectError(Date, Date), AssertionError);
assertThrows(() => assertExpectError(Error, Error), AssertionError);
assertThrows(() => assertExpectError(new Date(), Error), AssertionError);
assertThrows(() => assertExpectError(new Error(), Date), AssertionError);
},
});