UNPKG

1.57 kBJavaScriptView Raw
1var assert = require('assert'),
2 nunjucks = require('nunjucks');
3
4var loader = new nunjucks.FileSystemLoader('./test/contents/test.ch/templates'),
5 testEnvironment = new nunjucks.Environment(loader, {dev: true});
6
7var extensions = require('../lib/extensions');
8
9describe("ApiExtension", function(){
10 var testApi = {
11 invoke: function(name, params){
12 this[name].apply(this, params);
13 },
14 getTestObject: function(callback){
15 callback(null, {result: 'succeeded'});
16 }
17 };
18
19 testEnvironment.addExtension('Api', new extensions.ApiExtension(testApi));
20
21 describe("render", function(){
22 testEnvironment.render('test.apiextension.nunjuck.html', {}, function(err, result){
23 it('should be able to parse the template containing an api tag', function(){
24 assert(err == null);
25 });
26 it('and make the value available in the current context (and ignore newlines)', function(){
27 assert.equal("Test: succeeded", result);
28 });
29 });
30 try {
31 testEnvironment.render('test.apiextension.fail.nunjuck.html', {}, function(err, result){
32 it('should not be able to parse wrong syntax', function(){
33 assert(err);
34 console.log(err);
35 });
36 });
37 } catch(err){
38 it('should not be able to parse wrong syntax but currently throws errors', function(){
39 assert(true);
40 });
41 }
42 });
43});
\No newline at end of file