| 1 | import { NodePath } from "../../lib/index.js"; |
| 2 | |
| 3 | describe("NodePath", () => { |
| 4 | describe("setData/getData", () => { |
| 5 | it("can set default value", () => { |
| 6 | const path = new NodePath({}, {}); |
| 7 | |
| 8 | expect(path.getData("foo", "test")).toBe("test"); |
| 9 | }); |
| 10 | it("can set false", () => { |
| 11 | const path = new NodePath({}, {}); |
| 12 | path.setData("foo", false); |
| 13 | |
| 14 | expect(path.getData("foo", true)).toBe(false); |
| 15 | }); |
| 16 | |
| 17 | it("can set true", () => { |
| 18 | const path = new NodePath({}, {}); |
| 19 | path.setData("foo", true); |
| 20 | |
| 21 | expect(path.getData("foo", false)).toBe(true); |
| 22 | }); |
| 23 | |
| 24 | it("can set null", () => { |
| 25 | const path = new NodePath({}, {}); |
| 26 | path.setData("foo", null); |
| 27 | |
| 28 | expect(path.getData("foo", true)).toBe(null); |
| 29 | }); |
| 30 | |
| 31 | it("can use false as default", () => { |
| 32 | const path = new NodePath({}, {}); |
| 33 | |
| 34 | expect(path.getData("foo", false)).toBe(false); |
| 35 | }); |
| 36 | |
| 37 | it("does not use object base properties", () => { |
| 38 | const path = new NodePath({}, {}); |
| 39 | |
| 40 | expect(path.getData("__proto__", "test")).toBe("test"); |
| 41 | }); |
| 42 | |
| 43 | it("can use symbols as keys", () => { |
| 44 | const path = new NodePath({}, {}); |
| 45 | const symbol = Symbol("foo"); |
| 46 | path.setData(symbol, 42); |
| 47 | |
| 48 | expect(path.getData(symbol)).toBe(42); |
| 49 | }); |
| 50 | |
| 51 | describe("hasNode", () => { |
| 52 | it("returns false if node is null", () => { |
| 53 | const path = new NodePath({}, {}); |
| 54 | |
| 55 | expect(path.hasNode()).toBe(false); |
| 56 | }); |
| 57 | |
| 58 | it("returns true if node is not null", () => { |
| 59 | const path = new NodePath({}, {}); |
| 60 | path.node = {}; |
| 61 | |
| 62 | expect(path.hasNode()).toBe(true); |
| 63 | }); |
| 64 | }); |
| 65 | }); |
| 66 | }); |