res.render.js
This file
Path
test/res.render.js
257 lines · 6.0 KiB · JavaScript
Last changed by
deps: update example dependenciesDouglas Christopher Wilsonbefore adoption766b3ae
History of this fileTake it
The walk stopped after 200 commits: lines older than a10f695 point at it.
pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 1–2why, one step back12var express = require('../')remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 3why, one step back3 , request = require('supertest');pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
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 adoption328c6d3
line 9why, one step back9pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
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 adoption328c6d3
line 20why, one step back20pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
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 adoption328c6d3
line 23why, one step back23pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
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 adoption328c6d3
line 38why, one step back38pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 39–52why, 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 })50 51 it('should support index.<engine>', function(done){52 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 53why, one step back53pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 54–59why, one step back54 app.set('views', __dirname + '/fixtures');55 app.set('view engine', 'jade');5657 app.use(function(req, res){58 res.render('blog/post');59 });remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 60why, one step back60pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 61–64why, one step back61 request(app)62 .get('/')63 .expect('<h1>blog post</h1>', done);64 })remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 65why, one step back65pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 66–68why, one step back66 describe('when an error occurs', function(){67 it('should next(err)', function(done){68 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 69why, one step back69pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 70–74why, one step back70 app.set('views', __dirname + '/fixtures');7172 app.use(function(req, res){73 res.render('user.jade');74 });remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 75why, one step back75pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 76–81why, one step back76 app.use(function(err, req, res, next){77 res.end(err.message);78 });7980 request(app)81 .get('/')deps: update example dependenciesDouglas Christopher Wilsonbefore adoption766b3ae
line 82why, one step back82 .expect(/Cannot read property 'name' of undefined/, done);pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 83–84why, one step back83 })84 })remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 85why, one step back85pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 86–88why, one step back86 describe('when "view engine" is given', function(){87 it('should render the template', function(done){88 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 89why, one step back89pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 90–106why, one step back90 app.set('view engine', 'jade');91 app.set('views', __dirname + '/fixtures');9293 app.use(function(req, res){94 res.render('email');95 });9697 request(app)98 .get('/')99 .expect('<p>This is an email</p>', done);100 })101 })102 })103104 describe('.render(name, option)', function(){105 it('should render the template', function(done){106 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 107why, one step back107pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
line 108why, one step back108 app.set('views', __dirname + '/fixtures');remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 109why, one step back109pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 110–119why, one step back110 var user = { name: 'tobi' };111112 app.use(function(req, res){113 res.render('user.jade', { user: user });114 });115116 request(app)117 .get('/')118 .expect('<p>tobi</p>', done);119 })remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 120why, one step back120pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 121–122why, one step back121 it('should expose app.locals', function(done){122 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 123why, one step back123pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 124–134why, one step back124 app.set('views', __dirname + '/fixtures');125 app.locals.user = { name: 'tobi' };126127 app.use(function(req, res){128 res.render('user.jade');129 });130131 request(app)132 .get('/')133 .expect('<p>tobi</p>', done);134 })remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 135why, one step back135pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 136–137why, one step back136 it('should expose res.locals', function(done){137 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 138why, one step back138pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 139–149why, one step back139 app.set('views', __dirname + '/fixtures');140141 app.use(function(req, res){142 res.locals.user = { name: 'tobi' };143 res.render('user.jade');144 });145146 request(app)147 .get('/')148 .expect('<p>tobi</p>', done);149 })remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 150why, one step back150pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 151–152why, one step back151 it('should give precedence to res.locals over app.locals', function(done){152 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 153why, one step back153pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 154–168why, one step back154 app.set('views', __dirname + '/fixtures');155 app.locals.user = { name: 'tobi' };156157 app.use(function(req, res){158 res.locals.user = { name: 'jane' };159 res.render('user.jade', {});160 });161162 request(app)163 .get('/')164 .expect('<p>jane</p>', done);165 })166167 it('should give precedence to res.render() locals over res.locals', function(done){168 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 169why, one step back169pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 170–171why, one step back170 app.set('views', __dirname + '/fixtures');171 var jane = { name: 'jane' };remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 172why, one step back172pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 173–181why, one step back173 app.use(function(req, res){174 res.locals.user = { name: 'tobi' };175 res.render('user.jade', { user: jane });176 });177178 request(app)179 .get('/')180 .expect('<p>jane</p>', done);181 })remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 182why, one step back182pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 183–184why, one step back183 it('should give precedence to res.render() locals over app.locals', function(done){184 var app = express();remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 185why, one step back185pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 186–188why, one step back186 app.set('views', __dirname + '/fixtures');187 app.locals.user = { name: 'tobi' };188 var jane = { name: 'jane' };remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
line 189why, one step back189pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 190–252why, one step back190 app.use(function(req, res){191 res.render('user.jade', { user: jane });192 });193194 request(app)195 .get('/')196 .expect('<p>jane</p>', done);197 })198 })199200 describe('.render(name, options, fn)', function(){201 it('should pass the resulting string', function(done){202 var app = express();203204 app.set('views', __dirname + '/fixtures');205206 app.use(function(req, res){207 var tobi = { name: 'tobi' };208 res.render('user.jade', { user: tobi }, function(err, html){209 html = html.replace('tobi', 'loki');210 res.end(html);211 });212 });213214 request(app)215 .get('/')216 .expect('<p>loki</p>', done);217 })218 })219220 describe('.render(name, fn)', function(){221 it('should pass the resulting string', function(done){222 var app = express();223224 app.set('views', __dirname + '/fixtures');225226 app.use(function(req, res){227 res.locals.user = { name: 'tobi' };228 res.render('user.jade', function(err, html){229 html = html.replace('tobi', 'loki');230 res.end(html);231 });232 });233234 request(app)235 .get('/')236 .expect('<p>loki</p>', done);237 })238239 describe('when an error occurs', function(){240 it('should pass it to the callback', function(done){241 var app = express();242243 app.set('views', __dirname + '/fixtures');244245 app.use(function(req, res){246 res.render('user.jade', function(err){247 res.end(err.message);248 });249 });250251 request(app)252 .get('/')deps: update example dependenciesDouglas Christopher Wilsonbefore adoption766b3ae
line 253why, one step back253 .expect(/Cannot read property 'name' of undefined/, done);pin jade dev dep so tests do not breakTJ Holowaychukbefore adoptiona10f695
lines 254–257why, one step back254 })255 })256 })257})