-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpromise.spec.js
40 lines (36 loc) · 950 Bytes
/
promise.spec.js
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
40
import {assert} from 'chai';
import {sleep} from '../target/promise';
describe("Q4", function() {
this.timeout(2000);
it("with valid time.(1000)", (done) => {
var start = new Date().getTime();
sleep(1000).then((value) => {
assert.equal(value, 1000);
var end = new Date().getTime();
assert.ok(Math.abs(end - start - 1000) < 50);
done();
}).catch((value) => {
assert.fail();
});
});
it("with valid time.(0)", (done) => {
var start = new Date().getTime();
sleep(0).then((value) => {
assert.equal(value, 0);
var end = new Date().getTime();
assert.ok(Math.abs(end - start) < 50);
done();
}).catch((value) => {
assert.fail();
});
});
it("with invalid time", (done) => {
var start = new Date().getTime();
sleep(-1).then((value) => {
assert.fail();
}).catch((value) => {
assert.equal(value, -1);
done();
})
});
});