diff --git a/test/TemplateRenderNunjucksTest.js b/test/TemplateRenderNunjucksTest.js index 7376815d9..c4b78a5a0 100644 --- a/test/TemplateRenderNunjucksTest.js +++ b/test/TemplateRenderNunjucksTest.js @@ -1108,3 +1108,40 @@ test("addAsyncFilter for Nunjucks", async (t) => { let fn = await tr.getCompiledTemplate("
{{ 10 | fortytwo(2) }}
"); t.is(await fn(), "12
"); }); + +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("{{ 10 | fortytwo(2) }}
"); + t.is(await fn(), "12
"); +}); + +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("{{ 10 | fortytwo(2) }}
"); + t.is(await fn(), "12
"); +});