2 var express = require('../')
4 var path = require('path')
6 function render(path, options, fn) {
7 fs.readFile(path, 'utf8', function(err, str){
8 if (err) return fn(err);
9 str = str.replace('{{user.name}}', options.user.name);
14 describe('app', function(){
15 describe('.engine(ext, fn)', function(){
16 it('should map a template engine', function(done){
19 app.set('views', path.join(__dirname, 'fixtures'))
20 app.engine('.html', render);
21 app.locals.user = { name: 'tobi' };
23 app.render('user.html', function(err, str){
24 if (err) return done(err);
25 str.should.equal('<p>tobi</p>');
30 it('should throw when the callback is missing', function(){
33 app.engine('.html', null);
34 }).should.throw('callback function required');
37 it('should work without leading "."', function(done){
40 app.set('views', path.join(__dirname, 'fixtures'))
41 app.engine('html', render);
42 app.locals.user = { name: 'tobi' };
44 app.render('user.html', function(err, str){
45 if (err) return done(err);
46 str.should.equal('<p>tobi</p>');
51 it('should work "view engine" setting', function(done){
54 app.set('views', path.join(__dirname, 'fixtures'))
55 app.engine('html', render);
56 app.set('view engine', 'html');
57 app.locals.user = { name: 'tobi' };
59 app.render('user', function(err, str){
60 if (err) return done(err);
61 str.should.equal('<p>tobi</p>');
66 it('should work "view engine" with leading "."', function(done){
69 app.set('views', path.join(__dirname, 'fixtures'))
70 app.engine('.html', render);
71 app.set('view engine', '.html');
72 app.locals.user = { name: 'tobi' };
74 app.render('user', function(err, str){
75 if (err) return done(err);
76 str.should.equal('<p>tobi</p>');