app.engine.js
This file
Path
test/app.engine.js
65 lines · 1.7 KiB · JavaScript
Last changed by
throw when callback is not given to app.engine()TJ Holowaychukbefore adoption67ca22b
History of this fileTake it
The walk stopped after 200 commits: lines older than 81652c8 point at it.
Added app.del() testTj Holowaychukbefore adoption81652c8
lines 1–27why, one step back12var 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 })throw when callback is not given to app.engine()TJ Holowaychukbefore adoption67ca22b
lines 28–35why, one step back2829 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 })35Added app.del() testTj Holowaychukbefore adoption81652c8
lines 36–65why, one step back36 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})