UNPKG

docxtemplater

Version:

Generate docx, pptx, and xlsx from templates (Word, Powerpoint and Excel documents), from Node.js, the Browser and the command line

82 lines (81 loc) 2.3 kB
"use strict"; var _require = require("../utils.js"), resolveSoon = _require.resolveSoon; describe("Nullgetter", function () { it("should call nullgetter for loops synchonously", function () { return this.render({ name: "multi-loop.docx", data: { test2: "Value2" }, options: { paragraphLoop: true, nullGetter: function nullGetter(part) { if (part.module === "loop") { return [{ name: "Acme", users: [{ name: "John" }, { name: "James" }] }, { name: "Emca", users: [{ name: "Mary" }, { name: "Liz" }] }]; } } }, expectedName: "expected-multi-loop.docx" }); }); it("should call nullgetter for loops async", function () { return this.render({ name: "multi-loop.docx", data: { test2: "Value2" }, options: { paragraphLoop: true, nullGetter: function nullGetter(part) { if (part.module === "loop") { return resolveSoon([{ name: "Acme", users: resolveSoon([{ name: resolveSoon("John", 25) }, resolveSoon({ name: "James" })], 5) }, resolveSoon({ name: resolveSoon("Emca"), users: resolveSoon([{ name: "Mary" }, { name: "Liz" }]) }, 20)]); } } }, expectedName: "expected-multi-loop.docx", async: true }); }); it("should call nullGetter with empty rawxml", function () { return this.renderV4({ name: "table-raw-xml.docx", options: { nullGetter: function nullGetter(part) { if (part.module === "rawxml") { return "<w:p>\n <w:r>\n <w:rPr><w:color w:val=\"FF0000\"/></w:rPr>\n <w:t>UNDEFINED</w:t>\n </w:r>\n </w:p>"; } } }, expectedName: "expected-raw-xml-null.docx" }); }); });