-
-
Notifications
You must be signed in to change notification settings - Fork 380
/
Copy pathready.test.js
59 lines (53 loc) · 1.51 KB
/
ready.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import ready from "../../src/utils/ready";
describe("ready", () => {
it("should call callback if state is true", () => {
const cb = jest.fn();
const context = {
state: true,
stats: "stats",
};
ready(context, cb);
expect(cb.mock.calls.length).toEqual(1);
expect(cb.mock.calls[0]).toEqual(["stats"]);
});
it("should save callback and log req.url if state is false with req.url set", () => {
const cb = jest.fn();
const context = {
state: false,
stats: "stats",
logger: {
info: jest.fn(),
},
callbacks: [],
};
const req = {
url: "url",
};
ready(context, cb, req);
expect(cb).not.toBeCalled();
expect(context.logger.info.mock.calls.length).toEqual(1);
expect(context.logger.info.mock.calls[0]).toEqual([
"wait until bundle finished: url",
]);
expect(context.callbacks).toEqual([cb]);
});
it("should save callback and log callback.name if state is false with req.url not set", () => {
const cb = jest.fn();
const context = {
state: false,
stats: "stats",
logger: {
info: jest.fn(),
},
callbacks: [],
};
ready(context, cb);
expect(cb).not.toBeCalled();
expect(context.logger.info.mock.calls.length).toEqual(1);
// mockConstructor is the name of the jest.fn() function
expect(context.logger.info.mock.calls[0]).toEqual([
"wait until bundle finished: mockConstructor",
]);
expect(context.callbacks).toEqual([cb]);
});
});