/
index.js
66 lines (49 loc) 路 1.61 KB
/
index.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
60
61
62
63
64
65
66
import { NodePath } from "../../lib";
describe("NodePath", () => {
describe("setData/getData", () => {
it("can set default value", () => {
const path = new NodePath({}, {});
expect(path.getData("foo", "test")).toBe("test");
});
it("can set false", () => {
const path = new NodePath({}, {});
path.setData("foo", false);
expect(path.getData("foo", true)).toBe(false);
});
it("can set true", () => {
const path = new NodePath({}, {});
path.setData("foo", true);
expect(path.getData("foo", false)).toBe(true);
});
it("can set null", () => {
const path = new NodePath({}, {});
path.setData("foo", null);
expect(path.getData("foo", true)).toBe(null);
});
it("can use false as default", () => {
const path = new NodePath({}, {});
expect(path.getData("foo", false)).toBe(false);
});
it("does not use object base properties", () => {
const path = new NodePath({}, {});
expect(path.getData("__proto__", "test")).toBe("test");
});
it("can use symbols as keys", () => {
const path = new NodePath({}, {});
const symbol = Symbol("foo");
path.setData(symbol, 42);
expect(path.getData(symbol)).toBe(42);
});
describe("hasNode", () => {
it("returns true if node is null", () => {
const path = new NodePath({}, {});
expect(path.hasNode()).toBe(false);
});
it("returns false if node is not null", () => {
const path = new NodePath({}, {});
path.node = {};
expect(path.hasNode()).toBe(true);
});
});
});
});