res.render.js
This file
Path
test/res.render.js
272 lines · 6.3 KiB · JavaScript
Last changed by
update example dependenciesDouglas Christopher Wilsonbefore adoption203fb05
History of this fileTake it
The walk stopped after 200 commits: lines older than f47c0d9 point at it.
add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 1–2why, one step back12var express = require('../')remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 3why, one step back3 , request = require('supertest');add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 4–8why, one step back45describe('res', function(){6 describe('.render(name)', function(){7 it('should support absolute paths', function(done){8 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 9why, one step back9add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 10–19why, one step back10 app.locals.user = { name: 'tobi' };1112 app.use(function(req, res){13 res.render(__dirname + '/fixtures/user.jade');14 });1516 request(app)17 .get('/')18 .expect('<p>tobi</p>', done);19 })remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 20why, one step back20add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 21–22why, one step back21 it('should support absolute paths with "view engine"', function(done){22 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 23why, one step back23add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 24–37why, one step back24 app.locals.user = { name: 'tobi' };25 app.set('view engine', 'jade');2627 app.use(function(req, res){28 res.render(__dirname + '/fixtures/user');29 });3031 request(app)32 .get('/')33 .expect('<p>tobi</p>', done);34 })3536 it('should expose app.locals', function(done){37 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 38why, one step back38add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 39–49why, one step back39 app.set('views', __dirname + '/fixtures');40 app.locals.user = { name: 'tobi' };4142 app.use(function(req, res){43 res.render('user.jade');44 });4546 request(app)47 .get('/')48 .expect('<p>tobi</p>', done);49 })Merge pull request #1908 from visionmedia/locals-objectRoman Shtylmanbefore adoption991c2a9
lines 50–64why, one step back5051 it('should expose app.locals with `name` property', function(done){52 var app = express();5354 app.set('views', __dirname + '/fixtures');55 app.locals.name = 'tobi';5657 app.use(function(req, res){58 res.render('name.jade');59 });6061 request(app)62 .get('/')63 .expect('<p>tobi</p>', done);64 })remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 65why, one step back65add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 66–67why, one step back66 it('should support index.<engine>', function(done){67 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 68why, one step back68add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 69–74why, one step back69 app.set('views', __dirname + '/fixtures');70 app.set('view engine', 'jade');7172 app.use(function(req, res){73 res.render('blog/post');74 });remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 75why, one step back75add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 76–79why, one step back76 request(app)77 .get('/')78 .expect('<h1>blog post</h1>', done);79 })remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 80why, one step back80add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 81–83why, one step back81 describe('when an error occurs', function(){82 it('should next(err)', function(done){83 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 84why, one step back84add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 85–89why, one step back85 app.set('views', __dirname + '/fixtures');8687 app.use(function(req, res){88 res.render('user.jade');89 });remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 90why, one step back90add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 91–96why, one step back91 app.use(function(err, req, res, next){92 res.end(err.message);93 });9495 request(app)96 .get('/')update example dependenciesDouglas Christopher Wilsonbefore adoption203fb05
line 97why, one step back97 .expect(/Cannot read property '[^']+' of undefined/, done);add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 98–99why, one step back98 })99 })remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 100why, one step back100add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 101–103why, one step back101 describe('when "view engine" is given', function(){102 it('should render the template', function(done){103 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 104why, one step back104add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 105–121why, one step back105 app.set('view engine', 'jade');106 app.set('views', __dirname + '/fixtures');107108 app.use(function(req, res){109 res.render('email');110 });111112 request(app)113 .get('/')114 .expect('<p>This is an email</p>', done);115 })116 })117 })118119 describe('.render(name, option)', function(){120 it('should render the template', function(done){121 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 122why, one step back122add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
line 123why, one step back123 app.set('views', __dirname + '/fixtures');remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 124why, one step back124add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 125–134why, one step back125 var user = { name: 'tobi' };126127 app.use(function(req, res){128 res.render('user.jade', { user: user });129 });130131 request(app)132 .get('/')133 .expect('<p>tobi</p>', done);134 })remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 135why, one step back135add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 136–137why, one step back136 it('should expose app.locals', function(done){137 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 138why, one step back138add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 139–149why, one step back139 app.set('views', __dirname + '/fixtures');140 app.locals.user = { name: 'tobi' };141142 app.use(function(req, res){143 res.render('user.jade');144 });145146 request(app)147 .get('/')148 .expect('<p>tobi</p>', done);149 })remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 150why, one step back150add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 151–152why, one step back151 it('should expose res.locals', function(done){152 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 153why, one step back153add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 154–164why, one step back154 app.set('views', __dirname + '/fixtures');155156 app.use(function(req, res){157 res.locals.user = { name: 'tobi' };158 res.render('user.jade');159 });160161 request(app)162 .get('/')163 .expect('<p>tobi</p>', done);164 })remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 165why, one step back165add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 166–167why, one step back166 it('should give precedence to res.locals over app.locals', function(done){167 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 168why, one step back168add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 169–183why, one step back169 app.set('views', __dirname + '/fixtures');170 app.locals.user = { name: 'tobi' };171172 app.use(function(req, res){173 res.locals.user = { name: 'jane' };174 res.render('user.jade', {});175 });176177 request(app)178 .get('/')179 .expect('<p>jane</p>', done);180 })181182 it('should give precedence to res.render() locals over res.locals', function(done){183 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 184why, one step back184add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 185–186why, one step back185 app.set('views', __dirname + '/fixtures');186 var jane = { name: 'jane' };remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 187why, one step back187add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 188–196why, one step back188 app.use(function(req, res){189 res.locals.user = { name: 'tobi' };190 res.render('user.jade', { user: jane });191 });192193 request(app)194 .get('/')195 .expect('<p>jane</p>', done);196 })remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 197why, one step back197add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 198–199why, one step back198 it('should give precedence to res.render() locals over app.locals', function(done){199 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 200why, one step back200add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 201–203why, one step back201 app.set('views', __dirname + '/fixtures');202 app.locals.user = { name: 'tobi' };203 var jane = { name: 'jane' };remove unnecessary test/support/httpJonathan Ongbefore adoption643397e
line 204why, one step back204add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 205–267why, one step back205 app.use(function(req, res){206 res.render('user.jade', { user: jane });207 });208209 request(app)210 .get('/')211 .expect('<p>jane</p>', done);212 })213 })214215 describe('.render(name, options, fn)', function(){216 it('should pass the resulting string', function(done){217 var app = express();218219 app.set('views', __dirname + '/fixtures');220221 app.use(function(req, res){222 var tobi = { name: 'tobi' };223 res.render('user.jade', { user: tobi }, function(err, html){224 html = html.replace('tobi', 'loki');225 res.end(html);226 });227 });228229 request(app)230 .get('/')231 .expect('<p>loki</p>', done);232 })233 })234235 describe('.render(name, fn)', function(){236 it('should pass the resulting string', function(done){237 var app = express();238239 app.set('views', __dirname + '/fixtures');240241 app.use(function(req, res){242 res.locals.user = { name: 'tobi' };243 res.render('user.jade', function(err, html){244 html = html.replace('tobi', 'loki');245 res.end(html);246 });247 });248249 request(app)250 .get('/')251 .expect('<p>loki</p>', done);252 })253254 describe('when an error occurs', function(){255 it('should pass it to the callback', function(done){256 var app = express();257258 app.set('views', __dirname + '/fixtures');259260 app.use(function(req, res){261 res.render('user.jade', function(err){262 res.end(err.message);263 });264 });265266 request(app)267 .get('/')update example dependenciesDouglas Christopher Wilsonbefore adoption203fb05
line 268why, one step back268 .expect(/Cannot read property '[^']+' of undefined/, done);add Router.all() methodRoman Shtylmanbefore adoptionf47c0d9
lines 269–272why, one step back269 })270 })271 })272})