90 lines
1.4 KiB
JavaScript
90 lines
1.4 KiB
JavaScript
import {
|
|
cloneNode,
|
|
createNode,
|
|
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("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: {},
|
|
},
|
|
})
|
|
})
|
|
|
|
});
|
|
|
|
describe("isAstNode()", () => {
|
|
|
|
it("should import isAstNode()", () => {
|
|
expect(isAstNode).toBeDefined();
|
|
});
|
|
|
|
it("should return true if the node is an AST node", () => {
|
|
[
|
|
createNode(),
|
|
].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);
|
|
});
|
|
});
|
|
|
|
});
|
|
|