Add test such that it only should call prep once

This commit is contained in:
Dolan Miu
2019-09-22 19:09:34 +01:00
parent a9d4ebc898
commit c11af71ed7

View File

@ -1,7 +1,8 @@
import { assert, expect } from "chai"; import { assert, expect } from "chai";
import * as sinon from "sinon";
import { Formatter } from "export/formatter"; import { Formatter } from "export/formatter";
import * as file from "file"; import { Paragraph, TextRun } from "file";
import { CoreProperties } from "file/core-properties"; import { CoreProperties } from "file/core-properties";
import { Attributes } from "file/xml-components"; import { Attributes } from "file/xml-components";
@ -14,22 +15,22 @@ describe("Formatter", () => {
describe("#format()", () => { describe("#format()", () => {
it("should format simple paragraph", () => { it("should format simple paragraph", () => {
const paragraph = new file.Paragraph(""); const paragraph = new Paragraph("");
const newJson = formatter.format(paragraph); const newJson = formatter.format(paragraph);
assert.isDefined(newJson["w:p"]); assert.isDefined(newJson["w:p"]);
}); });
it("should remove xmlKeys", () => { it("should remove xmlKeys", () => {
const paragraph = new file.Paragraph(""); const paragraph = new Paragraph("");
const newJson = formatter.format(paragraph); const newJson = formatter.format(paragraph);
const stringifiedJson = JSON.stringify(newJson); const stringifiedJson = JSON.stringify(newJson);
assert(stringifiedJson.indexOf("xmlKeys") < 0); assert(stringifiedJson.indexOf("xmlKeys") < 0);
}); });
it("should format simple paragraph with bold text", () => { it("should format simple paragraph with bold text", () => {
const paragraph = new file.Paragraph(""); const paragraph = new Paragraph("");
paragraph.addRun( paragraph.addRun(
new file.TextRun({ new TextRun({
text: "test", text: "test",
bold: true, bold: true,
}), }),
@ -63,7 +64,7 @@ describe("Formatter", () => {
}); });
it("should should change 'p' tag into 'w:p' tag", () => { it("should should change 'p' tag into 'w:p' tag", () => {
const paragraph = new file.Paragraph(""); const paragraph = new Paragraph("");
const newJson = formatter.format(paragraph); const newJson = formatter.format(paragraph);
assert.isDefined(newJson["w:p"]); assert.isDefined(newJson["w:p"]);
}); });
@ -76,5 +77,13 @@ describe("Formatter", () => {
const newJson = formatter.format(properties); const newJson = formatter.format(properties);
assert.isDefined(newJson["cp:coreProperties"]); assert.isDefined(newJson["cp:coreProperties"]);
}); });
it("should call the prep method only once", () => {
const paragraph = new Paragraph("");
const spy = sinon.spy(paragraph, "prepForXml");
formatter.format(paragraph);
expect(spy.calledOnce).to.equal(true);
});
}); });
}); });