From 7ec9cff433fd7b62d9b9d8c85791b15dc1d310df Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Sat, 4 Feb 2023 23:50:37 +0000 Subject: [PATCH] Add tests for BuilderElement --- .../xml-components/simple-elements.spec.ts | 41 +++++++++++++++++++ src/file/xml-components/simple-elements.ts | 2 + 2 files changed, 43 insertions(+) create mode 100644 src/file/xml-components/simple-elements.spec.ts diff --git a/src/file/xml-components/simple-elements.spec.ts b/src/file/xml-components/simple-elements.spec.ts new file mode 100644 index 0000000000..e87f8a4937 --- /dev/null +++ b/src/file/xml-components/simple-elements.spec.ts @@ -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", + }, + }, + }); + }); + }); +}); diff --git a/src/file/xml-components/simple-elements.ts b/src/file/xml-components/simple-elements.ts index 6ed117b7ba..dab6f618bc 100644 --- a/src/file/xml-components/simple-elements.ts +++ b/src/file/xml-components/simple-elements.ts @@ -92,5 +92,7 @@ export class BuilderElement extends XmlComponent { if (options.attributes) { this.root.push(new NextAttributeComponent(options.attributes)); } + + // TODO: Children } }