app.engine.js
This file
Path
test/app.engine.js
81 lines · 2.1 KiB · JavaScript
Last changed by
tests: use path.join instead of concatenationchainhelenbefore adoptioneece385
History of this fileTake it
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
var express = require('../') , fs = require('fs');var path = require('path')
function render(path, options, fn) { fs.readFile(path, 'utf8', function(err, str){ if (err) return fn(err); str = str.replace('{{user.name}}', options.user.name); fn(null, str); });}
describe('app', function(){ describe('.engine(ext, fn)', function(){ it('should map a template engine', function(done){ var app = express();
app.set('views', path.join(__dirname, 'fixtures')) app.engine('.html', render); app.locals.user = { name: 'tobi' };
app.render('user.html', function(err, str){ if (err) return done(err); str.should.equal('<p>tobi</p>'); done(); }) })
it('should throw when the callback is missing', function(){ var app = express(); (function(){ app.engine('.html', null); }).should.throw('callback function required'); })
it('should work without leading "."', function(done){ var app = express();
app.set('views', path.join(__dirname, 'fixtures')) app.engine('html', render); app.locals.user = { name: 'tobi' };
app.render('user.html', function(err, str){ if (err) return done(err); str.should.equal('<p>tobi</p>'); done(); }) }) it('should work "view engine" setting', function(done){ var app = express();
app.set('views', path.join(__dirname, 'fixtures')) app.engine('html', render); app.set('view engine', 'html'); app.locals.user = { name: 'tobi' };
app.render('user', function(err, str){ if (err) return done(err); str.should.equal('<p>tobi</p>'); done(); }) }) it('should work "view engine" with leading "."', function(done){ var app = express();
app.set('views', path.join(__dirname, 'fixtures')) app.engine('.html', render); app.set('view engine', '.html'); app.locals.user = { name: 'tobi' };
app.render('user', function(err, str){ if (err) return done(err); str.should.equal('<p>tobi</p>'); done(); }) }) })})