-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.spec.js
More file actions
109 lines (90 loc) · 2.6 KB
/
Copy pathindex.spec.js
File metadata and controls
109 lines (90 loc) · 2.6 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* eslint-env jest */
const Zone = require("./");
const root = Zone.current;
describe("Zone", () => {
describe("root zone", () => {
it("has “<root>” name", () => {
expect(root.name).toBe("<root>");
});
it("has no parent", () => {
expect(root.parent).toBe(null);
});
it("has an object without prototype data", () => {
expect(root.data).toEqual({});
expect(Object.getPrototypeOf(root.data)).toBe(null);
});
});
describe("#fork()", () => {
it("creates a new child zone", () => {
const child = root.fork();
expect(child.name).toBe("<root> child");
expect(child.parent).toBe(root);
expect(child.data).toEqual({});
expect(Object.getPrototypeOf(child.data)).toBe(root.data);
});
it("accepts a name param", () => {
expect(root.fork("child").name).toBe("child");
});
it("accepts a ZoneSpec param", () => {
const child = root.fork({
name: "child",
properties: {
foo: "bar",
},
});
expect(child.name).toBe("child");
expect(child.data).toEqual({ foo: "bar" });
});
});
describe("#run()", () => {
it("runs a callback in the zone", done => {
const child = root.fork();
child.run(() => {
expect(Zone.current).toBe(child);
process.nextTick(() => {
expect(Zone.current).toBe(child);
done();
});
});
});
});
describe("#wrap()", () => {
it("creates a callback which runs in the zone", done => {
const child = root.fork();
child.wrap(() => {
expect(Zone.current).toBe(child);
process.nextTick(() => {
expect(Zone.current).toBe(child);
done();
});
})();
});
});
describe("#get()", () => {
it("returns a value associated with a key", () => {
root.data.root = "foo";
const child = root.fork();
child.data.child = "bar";
expect(child.get("root")).toBe("foo");
expect(child.get("child")).toBe("bar");
});
});
describe("#getZoneWith()", () => {
it("returns the zone which defines a key", () => {
root.data.root = "foo";
const child = root.fork();
child.data.child = "bar";
expect(child.getZoneWith("root")).toBe(root);
expect(child.getZoneWith("child")).toBe(child);
expect(child.getZoneWith("foo")).toBe(null);
});
});
// currently fails
it.skip("works with generators", () => {
const child = root.fork();
const iterator = child.run(function*() {
yield Zone.current;
});
expect(iterator.next().value).toBe(child);
});
});