From a315cb538b94753cce6a3ec971c55ac06db9f781 Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Mon, 22 Aug 2022 11:47:44 -0500 Subject: [PATCH] Testing #1913 async filters on nunjucks --- test/TemplateRenderNunjucksTest.js | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) 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

"); +});