diff options
Diffstat (limited to 'lib/models')
-rw-r--r-- | lib/models/__tests__/templateBlock.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/models/__tests__/templateBlock.js b/lib/models/__tests__/templateBlock.js index 44d53de..b8c426e 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', |