-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathasync.test.js
36 lines (36 loc) · 1.18 KB
/
async.test.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
import { thunkish } from "./async";
describe("async", () => {
describe("thunkish", () => {
it("starts with a producer and can have many consumers", () => {
let producer;
const consumeA = jest.fn();
const consumeB = jest.fn();
const consumer = thunkish(function(produce) {
producer = produce;
});
producer("foo");
producer("bar");
consumer(consumeA);
expect(consumeA).toHaveBeenCalledTimes(2);
producer("baz");
expect(consumeA).toHaveBeenCalledTimes(3);
expect(consumeB).not.toHaveBeenCalled();
consumer(consumeB);
expect(consumeB).toHaveBeenCalledTimes(3);
producer("done");
expect(consumeA).toHaveBeenCalledTimes(4);
expect(consumeB).toHaveBeenCalledTimes(4);
});
describe("toPromiseFactory", () => {
it("makes the thunkish behave like a promise factory", async () => {
let producer;
const consumer = thunkish(function(produce) {
producer = produce;
});
const next = consumer.toPromiseFactory();
producer("testing promise factory");
expect(await next()).toEqual("testing promise factory");
});
});
});
});