import { cloneNode, createAstNode, isAstNode, } 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("createAstNode()", () => { it("should import createAstNode()", () => { expect(createAstNode).toBeDefined(); }) it("should create a generic AST node with no arguments", () => { expect(createAstNode()).toEqual({ type: undefined, value: undefined, children: [], }) }) }); describe("isAstNode()", () => { it("should import isAstNode()", () => { expect(isAstNode).toBeDefined(); }); it("should return true if the node is an AST node", () => { [ createAstNode(), ].forEach(value => { expect(isAstNode(value)).toBe(true); }); }); it("should return true if the node is an AST node", () => { [ "string", "", null, undefined, {}, {a:1}, {children:[]}, ].forEach(value => { expect(isAstNode(value)).toBe(false); }); }); });