-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.test.ts
38 lines (31 loc) · 1.03 KB
/
error.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
import { assertStrictEq, assertThrowsAsync, prepareTest } from "../test.mod.ts";
import { MockData } from "./CONSTANTS.ts";
import { PollingObserver, OnfinishRejected, OnfinishValue } from "./mod.ts";
async function failsWhenConditionCallbackIsUndefined() {
await assertThrowsAsync(
async () => (new PollingObserver(undefined!) as unknown) as void,
TypeError,
`'conditionCallback' is not defined`
);
}
async function failsWhenErrorOccurs() {
const obs = new PollingObserver<MockData>(() => false);
const task = new Promise<OnfinishRejected>(yay => {
obs.onfinish = (d: OnfinishValue<unknown>) => yay(d as OnfinishRejected);
});
obs.observe(
async () => {
throw new Error("polling error");
},
{ interval: 1e3 }
);
const { status, reason } = await task;
assertStrictEq(status, "error");
assertStrictEq(reason instanceof Error, true);
assertStrictEq(reason.message, "polling error");
}
prepareTest(
[failsWhenConditionCallbackIsUndefined, failsWhenErrorOccurs],
"polling_observer",
"error"
);