diff --git a/src/handlebars.test.ts b/src/handlebars.test.ts index 41b00f5..6f36cf1 100644 --- a/src/handlebars.test.ts +++ b/src/handlebars.test.ts @@ -28,4 +28,15 @@ describe.concurrent("handlebars", () => { expect(result).toEqual("helpers: false"); }); + + it("can use an or helper without an else statement", async (ctx) => { + const template = Handlebars.compile( + "{{#or POSTGRES_VERSION KAFKA_USAGE}} services:{{/or}}" + ); + const result = template({ + POSTGRES_VERSION: "14" + }); + + expect(result).toEqual(" services:"); + }); }); diff --git a/src/handlebars.ts b/src/handlebars.ts index f4d4395..a580adb 100644 --- a/src/handlebars.ts +++ b/src/handlebars.ts @@ -1,17 +1,17 @@ import Handlebars from "handlebars"; import isObject from "lodash/isObject"; -Handlebars.registerHelper("or", function (context, ...params) { +Handlebars.registerHelper("or", function (...params) { const options = params[params.length - 1]; params.pop(); for (const value of params) { if (value) { - return options.fn(context); + return options.fn(); } } - return options.inverse(context); + return options.inverse(); }); export default Handlebars;