diff --git a/demo/89-template-document.ts b/demo/89-template-document.ts index 1220a6a8f6..547c77404d 100644 --- a/demo/89-template-document.ts +++ b/demo/89-template-document.ts @@ -1,7 +1,7 @@ // Patch a document with patches // Import from 'docx' rather than '../build' if you install from npm import * as fs from "fs"; -import { IPatch, patchDocument, PatchType, TextRun } from "../src"; +import { IPatch, patchDocument, PatchType, TextRun } from "../build"; export const font = "Trebuchet MS"; export const getPatches = (fields: { [key: string]: string }) => { diff --git a/src/patcher/paragraph-split-inject.spec.ts b/src/patcher/paragraph-split-inject.spec.ts index c0b8eec459..7b207ba82b 100644 --- a/src/patcher/paragraph-split-inject.spec.ts +++ b/src/patcher/paragraph-split-inject.spec.ts @@ -88,26 +88,56 @@ describe("paragraph-split-inject", () => { }); it("should continue if text run doesn't have text", () => { - const output = findRunElementIndexWithToken( - { - name: "w:p", - type: "element", - elements: [ - { - name: "w:r", - type: "element", - elements: [ - { - name: "w:t", - type: "element", - }, - ], - }, - ], - }, - "hello", - ); - expect(output).to.deep.equal(0); + expect(() => + findRunElementIndexWithToken( + { + name: "w:p", + type: "element", + elements: [ + { + name: "w:r", + type: "element", + elements: [ + { + name: "w:t", + type: "element", + }, + ], + }, + ], + }, + "hello", + ), + ).to.throw(); + }); + + it("should continue if text run doesn't have text", () => { + expect(() => + findRunElementIndexWithToken( + { + name: "w:p", + type: "element", + elements: [ + { + name: "w:r", + type: "element", + elements: [ + { + name: "w:t", + type: "element", + elements: [ + { + type: "text", + }, + ], + }, + ], + }, + ], + }, + "hello", + ), + ).to.throw(); }); }); diff --git a/src/patcher/paragraph-split-inject.ts b/src/patcher/paragraph-split-inject.ts index 3cb3a9705d..d7485e4991 100644 --- a/src/patcher/paragraph-split-inject.ts +++ b/src/patcher/paragraph-split-inject.ts @@ -12,7 +12,7 @@ export const findRunElementIndexWithToken = (paragraphElement: Element, token: s continue; } - if ((text.elements?.[0].text as string)?.includes(token)) { + if ((text.elements[0].text as string)?.includes(token)) { return i; } }