Fix tests and use proper types for disregarding XMLComponent
This commit is contained in:
@ -21,8 +21,10 @@ export class TableCellMargin extends XmlComponent {
|
||||
super("w:tblCellMar");
|
||||
}
|
||||
|
||||
public prepForXml(): IXmlableObject {
|
||||
return this.root.length > 0 ? super.prepForXml() : "";
|
||||
public prepForXml(): IXmlableObject | undefined {
|
||||
if (this.root.length > 0) {
|
||||
return super.prepForXml();
|
||||
}
|
||||
}
|
||||
|
||||
public addTopMargin(value: number, type: WidthType = WidthType.DXA): void {
|
||||
|
@ -8,8 +8,7 @@ describe("TableCellBorders", () => {
|
||||
describe("#prepForXml", () => {
|
||||
it("should not add empty borders element if there are no borders defined", () => {
|
||||
const tb = new TableCellBorders();
|
||||
const tree = new Formatter().format(tb);
|
||||
expect(tree).to.deep.equal("");
|
||||
expect(() => new Formatter().format(tb)).to.throw();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -29,8 +29,10 @@ export class TableCellBorders extends XmlComponent {
|
||||
super("w:tcBorders");
|
||||
}
|
||||
|
||||
public prepForXml(): IXmlableObject {
|
||||
return this.root.length > 0 ? super.prepForXml() : "";
|
||||
public prepForXml(): IXmlableObject | undefined {
|
||||
if (this.root.length > 0) {
|
||||
return super.prepForXml();
|
||||
}
|
||||
}
|
||||
|
||||
public addTopBorder(style: BorderStyle, size: number, color: string): TableCellBorders {
|
||||
|
@ -126,9 +126,13 @@ export class TableCell extends XmlComponent {
|
||||
return this;
|
||||
}
|
||||
|
||||
public prepForXml(): IXmlableObject {
|
||||
public prepForXml(): IXmlableObject | undefined {
|
||||
// Cells must end with a paragraph
|
||||
const retval = super.prepForXml();
|
||||
if (!retval) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const content = retval["w:tc"];
|
||||
if (!content[content.length - 1]["w:p"]) {
|
||||
content.push(new Paragraph().prepForXml());
|
||||
|
Reference in New Issue
Block a user