-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
78 lines (70 loc) · 2.02 KB
/
Copy pathtest.js
File metadata and controls
78 lines (70 loc) · 2.02 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const chai = require("chai");
require("chai-as-promised");
const { GateKeeper } = require("./GateKeeper");
describe("Gate Keeper", () => {
describe("calls only once", () => {
it("should only call once", function (done) {
const get = GateKeeper(async () => {
done();
});
get(1);
get(1);
});
it("should resolve the call twice", (done) => {
let calls = 0;
const get = GateKeeper(
() => new Promise((resolve) => setTimeout(resolve, 1))
);
get(2).then(() => {
calls++;
if (calls === 2) {
done();
}
});
get(2).then(() => {
calls++;
if (calls === 2) {
done();
}
});
// Call with a different value
get(1).then(() => {
calls++;
if (calls === 2) {
done();
}
});
get(1).then(() => {
calls++;
if (calls === 2) {
done();
}
});
});
});
describe("result should be equal", () => {
it("deep equal", (done) => {
let firstResult = null;
const get = GateKeeper(() => {
return new Promise((resolve) => {
setTimeout(() => {
resolve({
a: 1,
d: {
f: 5,
},
});
}, 1);
});
});
get(1).then((result) => (firstResult = result));
get(1).then((result) => {
if (result === firstResult) {
done();
} else {
done(1);
}
});
});
});
});