mirror of
https://github.com/hanzoai/babel.git
synced 2026-10-30 14:46:06 +00:00
67 lines
1.6 KiB
JavaScript
67 lines
1.6 KiB
JavaScript
import { NodePath } from "../../lib/index.js";
|
|
|
|
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 false if node is null", () => {
|
|
const path = new NodePath({}, {});
|
|
|
|
expect(path.hasNode()).toBe(false);
|
|
});
|
|
|
|
it("returns true if node is not null", () => {
|
|
const path = new NodePath({}, {});
|
|
path.node = {};
|
|
|
|
expect(path.hasNode()).toBe(true);
|
|
});
|
|
});
|
|
});
|
|
});
|