diff --git a/src/export/formatter.spec.ts b/src/export/formatter.spec.ts index bd6c9b7160..7ee05fa5d1 100644 --- a/src/export/formatter.spec.ts +++ b/src/export/formatter.spec.ts @@ -1,7 +1,8 @@ import { assert, expect } from "chai"; +import * as sinon from "sinon"; import { Formatter } from "export/formatter"; -import * as file from "file"; +import { Paragraph, TextRun } from "file"; import { CoreProperties } from "file/core-properties"; import { Attributes } from "file/xml-components"; @@ -14,22 +15,22 @@ describe("Formatter", () => { describe("#format()", () => { it("should format simple paragraph", () => { - const paragraph = new file.Paragraph(""); + const paragraph = new Paragraph(""); const newJson = formatter.format(paragraph); assert.isDefined(newJson["w:p"]); }); it("should remove xmlKeys", () => { - const paragraph = new file.Paragraph(""); + const paragraph = new Paragraph(""); const newJson = formatter.format(paragraph); const stringifiedJson = JSON.stringify(newJson); assert(stringifiedJson.indexOf("xmlKeys") < 0); }); it("should format simple paragraph with bold text", () => { - const paragraph = new file.Paragraph(""); + const paragraph = new Paragraph(""); paragraph.addRun( - new file.TextRun({ + new TextRun({ text: "test", bold: true, }), @@ -63,7 +64,7 @@ describe("Formatter", () => { }); it("should should change 'p' tag into 'w:p' tag", () => { - const paragraph = new file.Paragraph(""); + const paragraph = new Paragraph(""); const newJson = formatter.format(paragraph); assert.isDefined(newJson["w:p"]); }); @@ -76,5 +77,13 @@ describe("Formatter", () => { const newJson = formatter.format(properties); 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); + }); }); });