import { cloneNode, createNode, isNode, } from '../src/util.mjs'; describe("cloneNode()", () => { it("should import cloneNode()", () => { expect(cloneNode).toBeDefined(); }); it("should clone a node", () => { const node = { type: "root", children: [ { type: "element", tagName: "div", properties: {}, children: [], position: { start: { line: 1, column: 1, offset: 0, }, end: { line: 1, column: 12, offset: 11, }, }, }, ], }; expect(cloneNode(node)).toEqual(node); expect(cloneNode(node) === node).toBe(false); }); }); describe("createNode()", () => { it("should import createNode()", () => { expect(createNode).toBeDefined(); }) it("should create a generic AST node with no arguments", () => { expect(createNode()).toEqual({ type: 'created-node', data: { context: {}, }, }) }) it("should create a generic AST node with no arguments", () => { expect(createNode({type:"pig"})).toEqual({ type: 'pig', data: { context: {}, }, }) }) }); describe("isNode()", () => { it("should import isNode()", () => { expect(isNode).toBeDefined(); }); it("should return true if the node is an AST node", () => { [ createNode(), ].forEach(value => { expect(isNode(value)).toBe(true); }); }); it("should return true if the node is an AST node", () => { [ "string", "", null, undefined, {}, {a:1}, {children:[]}, ].forEach(value => { expect(isNode(value)).toBe(false); }); }); });