Files
docx-js/src/export/packer/packer.spec.ts

49 lines
1.4 KiB
TypeScript
Raw Normal View History

2018-07-01 02:26:23 +01:00
/* tslint:disable:typedef space-before-function-paren */
import { assert } from "chai";
import { stub } from "sinon";
import { File, Paragraph } from "../../file";
import { Packer } from "./packer";
2018-07-01 02:26:23 +01:00
describe("Packer", () => {
let packer: Packer;
let file: File;
2018-07-01 02:26:23 +01:00
beforeEach(() => {
file = new File({
2018-07-01 02:26:23 +01:00
creator: "Dolan Miu",
revision: "1",
lastModifiedBy: "Dolan Miu",
});
const paragraph = new Paragraph("test text");
const heading = new Paragraph("Hello world").heading1();
2018-07-01 02:26:23 +01:00
file.addParagraph(new Paragraph("title").title());
file.addParagraph(heading);
file.addParagraph(new Paragraph("heading 2").heading2());
file.addParagraph(paragraph);
packer = new Packer();
2018-07-01 02:26:23 +01:00
});
describe("#toBuffer()", () => {
2018-07-01 02:26:23 +01:00
it("should create a standard docx file", async function() {
this.timeout(99999999);
const buffer = await packer.toBuffer(file);
2018-07-01 02:26:23 +01:00
assert.isDefined(buffer);
assert.isTrue(buffer.byteLength > 0);
});
it("should handle exception if it throws any", () => {
// tslint:disable-next-line:no-any
const compiler = stub((packer as any).compiler, "compile");
2018-07-01 02:26:23 +01:00
compiler.throwsException();
return packer.toBuffer(file).catch((error) => {
2018-07-01 02:26:23 +01:00
assert.isDefined(error);
});
});
});
});