Skip to content

Commit

Permalink
🐛 Prevent handlebar to compile template if content is empty (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
frinyvonnick authored Feb 8, 2022
1 parent d28d88e commit 2684645
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/models/Screenshot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ describe("Screenshot", () => {
expect(screenshot.quality).toEqual(undefined);
});

it("should handle empty content", () => {
const screenshot = new Screenshot({
html,
content: {},
});

expect(screenshot.content).toEqual(undefined);
});

it("should set quality if type is jpeg", () => {
const screenshot = new Screenshot({
html,
Expand Down
6 changes: 5 additions & 1 deletion src/models/Screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Screenshot {
this.transparent = transparent;
this.type = type;
this.output = output;
this.content = content;
this.content = isEmpty(content) ? undefined : content;
this.selector = selector;
this.quality = type === "jpeg" ? quality : undefined;
}
Expand All @@ -48,3 +48,7 @@ export class Screenshot {
this.buffer = buffer;
}
}

function isEmpty(val: object) {
return val == null || !Object.keys(val).length;
}
14 changes: 14 additions & 0 deletions src/screenshot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ describe("beforeScreenshot", () => {
);
});

it("should not compile a screenshot if content is empty", async () => {
await makeScreenshot(page, {
screenshot: new Screenshot({
html: "<html><body>{{message}}</body></html>",
content: {},
}),
});

expect(page.setContent).toHaveBeenCalledWith(
"<html><body>{{message}}</body></html>",
expect.anything()
);
});

it("should wait until load event", async () => {
await makeScreenshot(page, {
screenshot: new Screenshot({
Expand Down

0 comments on commit 2684645

Please sign in to comment.