Skip to content

Commit

Permalink
Testing #1913 async filters on nunjucks
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Aug 22, 2022
1 parent cbaa674 commit a315cb5
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/TemplateRenderNunjucksTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1108,3 +1108,40 @@ test("addAsyncFilter for Nunjucks", async (t) => {
let fn = await tr.getCompiledTemplate("<p>{{ 10 | fortytwo(2) }}</p>");
t.is(await fn(), "<p>12</p>");
});

test("Asynchronous filters (via addNunjucksFilter) for Nunjucks", async (t) => {
let templateConfig = new TemplateConfig();
// works without async function (can return promise)
templateConfig.userConfig.addNunjucksFilter(
"fortytwo",
function (value1, value2, callback) {
setTimeout(function () {
callback(null, value1 + value2);
}, 100);
},
true
);

let tr = getNewTemplateRender("njk", null, templateConfig);

let fn = await tr.getCompiledTemplate("<p>{{ 10 | fortytwo(2) }}</p>");
t.is(await fn(), "<p>12</p>");
});

test("Asynchronous filters (via addNunjucksAsyncFilter) for Nunjucks", async (t) => {
let templateConfig = new TemplateConfig();
// works without async function (can return promise)
templateConfig.userConfig.addNunjucksAsyncFilter(
"fortytwo",
function (value1, value2, callback) {
setTimeout(function () {
callback(null, value1 + value2);
}, 100);
}
);

let tr = getNewTemplateRender("njk", null, templateConfig);

let fn = await tr.getCompiledTemplate("<p>{{ 10 | fortytwo(2) }}</p>");
t.is(await fn(), "<p>12</p>");
});

0 comments on commit a315cb5

Please sign in to comment.