Add tests for BuilderElement

This commit is contained in:
Dolan Miu
2023-02-04 23:50:37 +00:00
parent 3f979b9981
commit 7ec9cff433
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,41 @@
import { expect } from "chai";
import { Formatter } from "@export/formatter";
import { BuilderElement } from "./simple-elements";
describe("BuilderElement", () => {
describe.only("#constructor()", () => {
it("should create a simple BuilderElement", () => {
const element = new BuilderElement({
name: "test",
});
const tree = new Formatter().format(element);
expect(tree).to.deep.equal({
test: {},
});
});
it("should create a simple BuilderElement with attributes", () => {
const element = new BuilderElement<{ testAttr: string }>({
name: "test",
attributes: {
testAttr: {
key: "w:testAttr",
value: "test",
},
},
});
const tree = new Formatter().format(element);
expect(tree).to.deep.equal({
test: {
_attr: {
"w:testAttr": "test",
},
},
});
});
});
});

View File

@ -92,5 +92,7 @@ export class BuilderElement<T extends AttributeData> extends XmlComponent {
if (options.attributes) { if (options.attributes) {
this.root.push(new NextAttributeComponent(options.attributes)); this.root.push(new NextAttributeComponent(options.attributes));
} }
// TODO: Children
} }
} }