Skip to content
Myr

app.engine.js

This file

Path

test/app.engine.js

80 lines · 2.1 KiB · JavaScript

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than 2e68ddb point at it.

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

lines 1–80why, one step back
1
2var express = require('../')3 , fs = require('fs');45function render(path, options, fn) {6 fs.readFile(path, 'utf8', function(err, str){7 if (err) return fn(err);8 str = str.replace('{{user.name}}', options.user.name);9 fn(null, str);10 });11}1213describe('app', function(){14 describe('.engine(ext, fn)', function(){15 it('should map a template engine', function(done){16 var app = express();1718 app.set('views', __dirname + '/fixtures');19 app.engine('.html', render);20 app.locals.user = { name: 'tobi' };2122 app.render('user.html', function(err, str){23 if (err) return done(err);24 str.should.equal('<p>tobi</p>');25 done();26 })27 })2829 it('should throw when the callback is missing', function(){30 var app = express();31 (function(){32 app.engine('.html', null);33 }).should.throw('callback function required');34 })3536 it('should work without leading "."', function(done){37 var app = express();3839 app.set('views', __dirname + '/fixtures');40 app.engine('html', render);41 app.locals.user = { name: 'tobi' };4243 app.render('user.html', function(err, str){44 if (err) return done(err);45 str.should.equal('<p>tobi</p>');46 done();47 })48 })49 50 it('should work "view engine" setting', function(done){51 var app = express();5253 app.set('views', __dirname + '/fixtures');54 app.engine('html', render);55 app.set('view engine', 'html');56 app.locals.user = { name: 'tobi' };5758 app.render('user', function(err, str){59 if (err) return done(err);60 str.should.equal('<p>tobi</p>');61 done();62 })63 })64 65 it('should work "view engine" with leading "."', function(done){66 var app = express();6768 app.set('views', __dirname + '/fixtures');69 app.engine('.html', render);70 app.set('view engine', '.html');71 app.locals.user = { name: 'tobi' };7273 app.render('user', function(err, str){74 if (err) return done(err);75 str.should.equal('<p>tobi</p>');76 done();77 })78 })79 })80})