-
Notifications
You must be signed in to change notification settings - Fork 2
/
Sleep.test.ts
38 lines (31 loc) · 1.04 KB
/
Sleep.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 "source-map-support/register";
import * as assert from 'assert';
import 'mocha';
import { createTask } from './Task';
import CancellationToken from 'cancellationtoken';
import Sleep from "./Sleep";
let unhandledRejection: number = 0;
function cleanupUnhandledRejection() {
unhandledRejection = 0;
}
function hadUnhandledRejection() {
return unhandledRejection !== 0;
}
process.on('unhandledRejection', (reason, p) => {
console.log('rejected promise : ' + (p as any).uid);
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
unhandledRejection++;
// application specific logging, throwing an error, or other logic here
});
describe("Task", ()=> {
beforeEach(cleanupUnhandledRejection);
afterEach(()=> {
assert.equal(hadUnhandledRejection(), false);
});
it("Sleep", async()=>{
const start = new Date();
await Sleep(CancellationToken.CONTINUE, 20);
const end = new Date();
assert.ok(end.getTime() - start.getTime() >= 20, "Sleep actually sleeps");
});
});