diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-05-02 09:19:57 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-05-02 09:19:57 +0200 |
commit | 793fada0fbb27db69fc163cbda33a4c0dc8cf1e2 (patch) | |
tree | 42a9e2f777386fc966753db3a716a1e5c93e22d2 /lib/models | |
parent | 494ba78156eb29a782ee00cfea11ea558a50618c (diff) | |
download | gitbook-793fada0fbb27db69fc163cbda33a4c0dc8cf1e2.zip gitbook-793fada0fbb27db69fc163cbda33a4c0dc8cf1e2.tar.gz gitbook-793fada0fbb27db69fc163cbda33a4c0dc8cf1e2.tar.bz2 |
Add test for async template block
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', |