Write tests and simplify logic
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
// Patch a document with patches
|
// Patch a document with patches
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
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 font = "Trebuchet MS";
|
||||||
export const getPatches = (fields: { [key: string]: string }) => {
|
export const getPatches = (fields: { [key: string]: string }) => {
|
||||||
|
@ -88,26 +88,56 @@ describe("paragraph-split-inject", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should continue if text run doesn't have text", () => {
|
it("should continue if text run doesn't have text", () => {
|
||||||
const output = findRunElementIndexWithToken(
|
expect(() =>
|
||||||
{
|
findRunElementIndexWithToken(
|
||||||
name: "w:p",
|
{
|
||||||
type: "element",
|
name: "w:p",
|
||||||
elements: [
|
type: "element",
|
||||||
{
|
elements: [
|
||||||
name: "w:r",
|
{
|
||||||
type: "element",
|
name: "w:r",
|
||||||
elements: [
|
type: "element",
|
||||||
{
|
elements: [
|
||||||
name: "w:t",
|
{
|
||||||
type: "element",
|
name: "w:t",
|
||||||
},
|
type: "element",
|
||||||
],
|
},
|
||||||
},
|
],
|
||||||
],
|
},
|
||||||
},
|
],
|
||||||
"hello",
|
},
|
||||||
);
|
"hello",
|
||||||
expect(output).to.deep.equal(0);
|
),
|
||||||
|
).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();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ export const findRunElementIndexWithToken = (paragraphElement: Element, token: s
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((text.elements?.[0].text as string)?.includes(token)) {
|
if ((text.elements[0].text as string)?.includes(token)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user