From 793fada0fbb27db69fc163cbda33a4c0dc8cf1e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Mon, 2 May 2016 09:19:57 +0200 Subject: [PATCH] Add test for async template block --- lib/models/__tests__/templateBlock.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/models/__tests__/templateBlock.js b/lib/models/__tests__/templateBlock.js index 44d53de63..b8c426ed6 100644 --- a/lib/models/__tests__/templateBlock.js +++ b/lib/models/__tests__/templateBlock.js @@ -73,6 +73,29 @@ describe('TemplateBlock', function() { }); }); + pit('must accept an async function', function() { + var templateBlock = TemplateBlock.create('sayhello', function(block) { + return Promise() + .then(function() { + return 'Hello ' + block.body; + }); + }); + + // Create a fresh Nunjucks environment + var env = new nunjucks.Environment(null, { autoescape: false }); + + // Add template block to environement + var Ext = templateBlock.toNunjucksExt(); + env.addExtension(templateBlock.getExtensionName(), new Ext()); + + // Render a template using the block + var src = '{% sayhello %}Samy{% endsayhello %}'; + return Promise.nfcall(env.renderString.bind(env), src) + .then(function(res) { + expect(res).toBe('Hello Samy'); + }); + }); + pit('must handle nested blocks', function() { var templateBlock = new TemplateBlock({ name: 'yoda',