Add test for async template block

This commit is contained in:
Samy Pessé
2016-05-02 09:19:57 +02:00
parent 494ba78156
commit 793fada0fb
+23
View File
@@ -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',