improve test coverage

This commit is contained in:
Tom Hunkapiller
2021-05-26 10:14:19 +03:00
parent 5a52541136
commit 05a6ab77cc
7 changed files with 182 additions and 20 deletions

View File

@ -1,23 +1,62 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { XmlComponent } from "./";
import { Attributes, BaseXmlComponent, XmlComponent } from "./";
class TestComponent extends XmlComponent {}
class TestComponent extends XmlComponent {
public push(el: BaseXmlComponent): void {
this.root.push(el);
}
}
describe("XmlComponent", () => {
let xmlComponent: TestComponent;
beforeEach(() => {
xmlComponent = new TestComponent("w:test");
});
describe("#constructor()", () => {
it("should create an Xml Component which has the correct rootKey", () => {
const xmlComponent = new TestComponent("w:test");
const tree = new Formatter().format(xmlComponent);
expect(tree).to.deep.equal({
"w:test": {},
});
});
it("should handle children elements", () => {
const xmlComponent = new TestComponent("w:test");
xmlComponent.push(
new Attributes({
val: "test",
}),
);
xmlComponent.push(new TestComponent("innerTest"));
const tree = new Formatter().format(xmlComponent);
expect(tree).to.deep.equal({
"w:test": [
{
_attr: {
"w:val": "test",
},
},
{
innerTest: {},
},
],
});
});
it("should hoist attrs if only attrs are present", () => {
const xmlComponent = new TestComponent("w:test");
xmlComponent.push(
new Attributes({
val: "test",
}),
);
const tree = new Formatter().format(xmlComponent);
expect(tree).to.deep.equal({
"w:test": {
_attr: {
"w:val": "test",
},
},
});
});
});
});