Skip to content
Myr

res.render.js

This file

Path

test/res.render.js

257 lines · 6.0 KiB · JavaScript

Last changed by

adjust locals testsTJ Holowaychukbefore adoption1029b0b

History of this file

Take it

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

`make test` now runs unit / acceptance testsTJ Holowaychukbefore adoptionbabeb46

lines 1–17why, one step back
1
2var express = require('../')3 , request = require('./support/http');45describe('res', function(){6 describe('.render(name)', function(){7 it('should support absolute paths', function(done){8 var app = express();9 10 app.locals.user = { name: 'tobi' };1112 app.use(function(req, res){13 res.render(__dirname + '/fixtures/user.jade');14 });1516 request(app)17 .get('/')

updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e

line 18why, one step back
18 .expect('<p>tobi</p>', done);

`make test` now runs unit / acceptance testsTJ Holowaychukbefore adoptionbabeb46

lines 19–32why, one step back
19 })
20 21 it('should support absolute paths with "view engine"', function(done){22 var app = express();23 24 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('/')

updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e

line 33why, one step back
33 .expect('<p>tobi</p>', done);

`make test` now runs unit / acceptance testsTJ Holowaychukbefore adoptionbabeb46

lines 34–47why, one step back
34 })
3536 it('should expose app.locals', function(done){37 var app = express();38 39 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('/')

updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e

line 48why, one step back
48 .expect('<p>tobi</p>', done);

`make test` now runs unit / acceptance testsTJ Holowaychukbefore adoptionbabeb46

lines 49–62why, one step back
49 })
50 51 it('should support index.<engine>', function(done){52 var app = express();53 54 app.set('views', __dirname + '/fixtures');55 app.set('view engine', 'jade');5657 app.use(function(req, res){58 res.render('blog/post');59 });60 61 request(app)62 .get('/')

updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e

line 63why, one step back
63 .expect('<h1>blog post</h1>', done);

`make test` now runs unit / acceptance testsTJ Holowaychukbefore adoptionbabeb46

lines 64–81why, one step back
64 })
65 66 describe('when an error occurs', function(){67 it('should next(err)', function(done){68 var app = express();69 70 app.set('views', __dirname + '/fixtures');7172 app.use(function(req, res){73 res.render('user.jade');74 });75 76 app.use(function(err, req, res, next){77 res.end(err.message);78 });7980 request(app)81 .get('/')

updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e

line 82why, one step back
82 .expect(/user is not defined/, done);

`make test` now runs unit / acceptance testsTJ Holowaychukbefore adoptionbabeb46

lines 83–98why, one step back
83 })
84 })85 86 describe('when "view engine" is given', function(){87 it('should render the template', function(done){88 var app = express();89 90 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('/')

updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e

line 99why, one step back
99 .expect('<p>This is an email</p>', done);

`make test` now runs unit / acceptance testsTJ Holowaychukbefore adoptionbabeb46

lines 100–117why, one step back
100 })
101 })102 })103104 describe('.render(name, option)', function(){105 it('should render the template', function(done){106 var app = express();107 108 app.set('views', __dirname + '/fixtures');109 110 var user = { name: 'tobi' };111112 app.use(function(req, res){113 res.render('user.jade', { user: user });114 });115116 request(app)117 .get('/')

updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e

line 118why, one step back
118 .expect('<p>tobi</p>', done);

`make test` now runs unit / acceptance testsTJ Holowaychukbefore adoptionbabeb46

lines 119–127why, one step back
119 })
120 121 it('should expose app.locals', function(done){122 var app = express();123 124 app.set('views', __dirname + '/fixtures');125 app.locals.user = { name: 'tobi' };126127 app.use(function(req, res){

adjust locals testsTJ Holowaychukbefore adoption1029b0b

line 128why, one step back
128 res.render('user.jade');

`make test` now runs unit / acceptance testsTJ Holowaychukbefore adoptionbabeb46

lines 129–132why, one step back
129 });
130131 request(app)132 .get('/')

updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e

line 133why, one step back
133 .expect('<p>tobi</p>', done);

`make test` now runs unit / acceptance testsTJ Holowaychukbefore adoptionbabeb46

lines 134–142why, one step back
134 })
135 136 it('should expose res.locals', function(done){137 var app = express();138 139 app.set('views', __dirname + '/fixtures');140141 app.use(function(req, res){142 res.locals.user = { name: 'tobi' };

adjust locals testsTJ Holowaychukbefore adoption1029b0b

line 143why, one step back
143 res.render('user.jade');

`make test` now runs unit / acceptance testsTJ Holowaychukbefore adoptionbabeb46

lines 144–147why, one step back
144 });
145146 request(app)147 .get('/')

updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e

line 148why, one step back
148 .expect('<p>tobi</p>', done);

`make test` now runs unit / acceptance testsTJ Holowaychukbefore adoptionbabeb46

lines 149–163why, one step back
149 })
150 151 it('should give precedence to res.locals over app.locals', function(done){152 var app = express();153 154 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('/')

updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e

line 164why, one step back
164 .expect('<p>jane</p>', done);

`make test` now runs unit / acceptance testsTJ Holowaychukbefore adoptionbabeb46

lines 165–179why, one step back
165 })
166167 it('should give precedence to res.render() locals over res.locals', function(done){168 var app = express();169 170 app.set('views', __dirname + '/fixtures');171 var jane = { name: 'jane' };172 173 app.use(function(req, res){174 res.locals.user = { name: 'tobi' };175 res.render('user.jade', { user: jane });176 });177178 request(app)179 .get('/')

updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e

line 180why, one step back
180 .expect('<p>jane</p>', done);

`make test` now runs unit / acceptance testsTJ Holowaychukbefore adoptionbabeb46

lines 181–195why, one step back
181 })
182 183 it('should give precedence to res.render() locals over app.locals', function(done){184 var app = express();185 186 app.set('views', __dirname + '/fixtures');187 app.locals.user = { name: 'tobi' };188 var jane = { name: 'jane' };189 190 app.use(function(req, res){191 res.render('user.jade', { user: jane });192 });193194 request(app)195 .get('/')

updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e

line 196why, one step back
196 .expect('<p>jane</p>', done);

`make test` now runs unit / acceptance testsTJ Holowaychukbefore adoptionbabeb46

lines 197–215why, one step back
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('/')

updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e

line 216why, one step back
216 .expect('<p>loki</p>', done);

`make test` now runs unit / acceptance testsTJ Holowaychukbefore adoptionbabeb46

lines 217–235why, one step back
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('/')

updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e

line 236why, one step back
236 .expect('<p>loki</p>', done);

`make test` now runs unit / acceptance testsTJ Holowaychukbefore adoptionbabeb46

lines 237–252why, one step back
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('/')

updated tests to use "supertest"TJ Holowaychukbefore adoption0f5560e

line 253why, one step back
253 .expect(/is not defined/, done);

`make test` now runs unit / acceptance testsTJ Holowaychukbefore adoptionbabeb46

lines 254–257why, one step back
254 })
255 })256 })257})