view.test.js
This file
Path
test/view.test.js
283 lines · 8.9 KiB · JavaScript
Last changed by
res.render() using res.send()Tj Holowaychukbefore adoptioncba985b
History of this fileTake it
The walk stopped after 200 commits: lines older than 9449c4b point at it.
Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
lines 1–5why, one step back12/**3 * Module dependencies.4 */5Added support for partial(view, array) as collectionTj Holowaychukbefore adoption22100f7
line 6why, one step back6var express = require('express'),Merge branch 'view-helpers' into connectTj Holowaychukbefore adoptionddbef0b
lines 7–8why, one step back7 connect = require('connect'),8 view = require('express/view');Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
lines 9–11why, one step back910module.exports = {11 'test #render()': function(assert){Added invalid view testTj Holowaychukbefore adoption0e7d39a
line 12why, one step back12 var app = express.createServer(connect.errorHandler({ showMessage: true }));Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
line 13why, one step back13 app.set('views', __dirname + '/fixtures');Added default view engine supportTj Holowaychukbefore adoptiona75a119
line 14why, one step back14 app.set('view engine', 'jade');Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
lines 15–18why, one step back1516 app.get('/', function(req, res){17 res.render('index.jade', { layout: false });18 });Added default view engine supportTj Holowaychukbefore adoptiona75a119
lines 19–21why, one step back19 app.get('/jade', function(req, res){20 res.render('index', { layout: false });21 });Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
lines 22–24why, one step back22 app.get('/haml', function(req, res){23 res.render('hello.haml', { layout: false });24 });Added view callback testTj Holowaychukbefore adoption55a2980
lines 25–30why, one step back25 app.get('/callback', function(req, res){26 res.render('hello.haml', { layout: false }, function(err, str){27 assert.ok(!err);28 res.send(str.replace('Hello World', ':)'));29 });30 });Added invalid view testTj Holowaychukbefore adoption0e7d39a
lines 31–33why, one step back31 app.get('/invalid', function(req, res){32 res.render('invalid.jade', { layout: false });33 });Added view callback error testTj Holowaychukbefore adoption8beae06
lines 34–38why, one step back34 app.get('/error', function(req, res){35 res.render('invalid.jade', { layout: false }, function(err){36 res.send(err.arguments[0]);37 });38 });Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
lines 39–41why, one step back3940 assert.response(app,41 { url: '/' },res.render() using res.send()Tj Holowaychukbefore adoptioncba985b
line 42why, one step back42 { body: '<p>Welcome</p>', headers: { 'Content-Type': 'text/html; charset=utf-8' }});Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
line 43why, one step back43 assert.response(app,Added default view engine supportTj Holowaychukbefore adoptiona75a119
lines 44–46why, one step back44 { url: '/jade' },45 { body: '<p>Welcome</p>' });46 assert.response(app,Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
lines 47–48why, one step back47 { url: '/haml' },48 { body: '\n<p>Hello World</p>' });Added view callback testTj Holowaychukbefore adoption55a2980
lines 49–51why, one step back49 assert.response(app,50 { url: '/callback' },51 { body: '\n<p>:)</p>' });Added view callback error testTj Holowaychukbefore adoption8beae06
lines 52–54why, one step back52 assert.response(app,53 { url: '/error' },54 { body: 'doesNotExist' });Added invalid view testTj Holowaychukbefore adoption0e7d39a
lines 55–60why, one step back55 assert.response(app,56 { url: '/invalid' },57 function(res){58 assert.ok(res.body.indexOf('ReferenceError') >= 0);59 assert.ok(res.body.indexOf('doesNotExist') >= 0);60 });Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
lines 61–65why, one step back61 },62 63 'test #render() layout': function(assert){64 var app = express.createServer();65 app.set('views', __dirname + '/fixtures');Added default view engine supportTj Holowaychukbefore adoptiona75a119
line 66why, one step back66 app.set('view engine', 'jade');Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
lines 67–69why, one step back6768 app.get('/', function(req, res){69 res.render('index.jade');Added default view engine supportTj Holowaychukbefore adoptiona75a119
lines 70–72why, one step back70 });71 app.get('/jade', function(req, res){72 res.render('index');Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
lines 73–84why, one step back73 });7475 assert.response(app,76 { url: '/' },77 { body: '<html><body><p>Welcome</p></body></html>' });78 },79 80 'test #render() specific layout': function(assert){81 var app = express.createServer();82 app.set('views', __dirname + '/fixtures');8384 app.get('/', function(req, res){Added support for passing of layout name without extensionTj Holowaychukbefore adoptiona461815
line 85why, one step back85 res.render('index.jade', { layout: 'cool-layout.jade' });Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
line 86why, one step back86 });Added support for passing of layout name without extensionTj Holowaychukbefore adoptiona461815
lines 87–89why, one step back87 app.get('/no-ext', function(req, res){88 res.render('index.jade', { layout: 'cool-layout' });89 });Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
lines 90–92why, one step back9091 assert.response(app,92 { url: '/' },Added support for passing of layout name without extensionTj Holowaychukbefore adoptiona461815
lines 93–95why, one step back93 { body: '<cool><p>Welcome</p></cool>' });94 assert.response(app,95 { url: '/no-ext' },Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
lines 96–98why, one step back96 { body: '<cool><p>Welcome</p></cool>' });97 },98 Added test for specific layouts with "view engine" setTj Holowaychukbefore adoptioneedf54b
lines 99–112why, one step back99 'test #render() specific layout "view engine"': function(assert){100 var app = express.createServer();101 app.set('views', __dirname + '/fixtures');102 app.set('view engine', 'jade');103 104 app.get('/', function(req, res){105 res.render('index', { layout: 'cool-layout' });106 });107 108 assert.response(app,109 { url: '/' },110 { body: '<cool><p>Welcome</p></cool>' });111 },112 Renamed Server#helpers() to Server#dynamicHelpers()Tj Holowaychukbefore adoption92f1557
line 113why, one step back113 'test #render() view helpers': function(assert){Added dynamic view helper support. Closes #349Tj Holowaychukbefore adoption9ef8ea9
lines 114–116why, one step back114 var app = express.createServer();115 app.set('views', __dirname + '/fixtures');116Renamed Server#helpers() to Server#dynamicHelpers()Tj Holowaychukbefore adoption92f1557
line 117why, one step back117 app.helpers({ Added dynamic view helper support. Closes #349Tj Holowaychukbefore adoption9ef8ea9
line 118why, one step back118 lastName: 'holowaychuk',Renamed Server#helpers() to Server#dynamicHelpers()Tj Holowaychukbefore adoption92f1557
lines 119–124why, one step back119 foo: function(){120 return 'bar'; 121 }122 });123124 var ret = app.dynamicHelpers({Added assertions for dynamic helper params and scopeTj Holowaychukbefore adoption8e487ba
lines 125–129why, one step back125 session: function(req, res, params){126 assert.equal('object', typeof req, 'Test dynamic helper req');127 assert.equal('object', typeof req, 'Test dynamic helper res');128 assert.equal('object', typeof req, 'Test dynamic helper params');129 assert.ok(this instanceof express.Server, 'Test dynamic helper app scope');Added dynamic view helper support. Closes #349Tj Holowaychukbefore adoption9ef8ea9
lines 130–132why, one step back130 return req.session;131 }132 });Renamed Server#helpers() to Server#dynamicHelpers()Tj Holowaychukbefore adoption92f1557
lines 133–134why, one step back133134 assert.equal(app, ret, 'Server#helpers() is not chainable');Added dynamic view helper support. Closes #349Tj Holowaychukbefore adoption9ef8ea9
lines 135–142why, one step back135 136 app.get('/', function(req, res){137 req.session = { name: 'tj' };138 res.render('dynamic-helpers.jade', { layout: false });139 });140 141 assert.response(app,142 { url: '/' },Renamed Server#helpers() to Server#dynamicHelpers()Tj Holowaychukbefore adoption92f1557
line 143why, one step back143 { body: '<p>tj holowaychuk bar</p>' });Added dynamic view helper support. Closes #349Tj Holowaychukbefore adoption9ef8ea9
lines 144–145why, one step back144 },145 Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
lines 146–149why, one step back146 'test #partial()': function(assert){147 var app = express.createServer();148 app.set('views', __dirname + '/fixtures');149Added support for partial(view, array) as collectionTj Holowaychukbefore adoption22100f7
line 150why, one step back150 // Auto-assigned local w/ collection optionMerge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
lines 151–153why, one step back151 app.get('/', function(req, res){152 res.render('items.jade', { locals: { items: ['one', 'two'] }});153 });Added support for partial(view, array) as collectionTj Holowaychukbefore adoption22100f7
lines 154–155why, one step back154 155 assert.response(app,Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
lines 156–157why, one step back156 { url: '/' },157 { body: '<html><body><ul><li>one</li><li>two</li></ul></body></html>' });Added support for partial(view, array) as collectionTj Holowaychukbefore adoption22100f7
lines 158–187why, one step back158159 // Auto-assigned local w/ collection array 160 var movies = [161 { title: 'Nightmare Before Christmas', director: 'Tim Burton' },162 { title: 'Avatar', director: 'James Cameron' }163 ];164 app.get('/movies', function(req, res){165 res.render('movies.jade', { locals: { movies: movies }});166 });167 168 var html = [169 '<html>',170 '<body>',171 '<ul>',172 '<li>',173 '<div class="title">Nightmare Before Christmas</div>',174 '<div class="director">Tim Burton</div>',175 '</li>',176 '<li>',177 '<div class="title">Avatar</div>',178 '<div class="director">James Cameron</div>',179 '</li>',180 '</ul>',181 '</body>',182 '</html>'183 ].join('');184185 assert.response(app,186 { url: '/movies' },187 { body: html });Added collection "as" option testTj Holowaychukbefore adoption5544c5d
line 188why, one step back188 Added as: global supportTj Holowaychukbefore adoptiona32c7d5
line 189why, one step back189 // as: str collection optionAdded collection "as" option testTj Holowaychukbefore adoption5544c5d
lines 190–199why, one step back190 app.get('/user', function(req, res){191 res.send(res.partial('user.jade', {192 as: 'person',193 collection: [{ name: 'tj' }]194 }));195 });196 197 assert.response(app,198 { url: '/user' },199 { body: '<p>tj</p>' });Added as: this supportTj Holowaychukbefore adoptionedfb18b
line 200why, one step back200 Added as: global supportTj Holowaychukbefore adoptiona32c7d5
line 201why, one step back201 // as: this collection optionAdded as: this supportTj Holowaychukbefore adoptionedfb18b
lines 202–204why, one step back202 app.get('/person', function(req, res){203 res.send(res.partial('person.jade', {204 as: this,Added partial tests for collection locals + passed localsTj Holowaychukbefore adoptionf86f1e8
lines 205–206why, one step back205 collection: [{ name: 'tj' }],206 locals: { label: 'name:' }Added as: this supportTj Holowaychukbefore adoptionedfb18b
lines 207–211why, one step back207 }));208 });209 210 assert.response(app,211 { url: '/person' },Added partial tests for collection locals + passed localsTj Holowaychukbefore adoptionf86f1e8
line 212why, one step back212 { body: '<p>name: tj</p>' });Added as: global supportTj Holowaychukbefore adoptiona32c7d5
lines 213–224why, one step back213214 // as: global collection option215 app.get('/videos', function(req, res){216 res.send(res.partial('video.jade', {217 as: global,218 collection: movies219 }));220 });221222 assert.response(app,223 { url: '/videos' },224 { body: '<p>Tim Burton</p><p>James Cameron</p>' });Added view test for magic localsTj Holowaychukbefore adoptionfcf691d
lines 225–236why, one step back225 226 // Magic variables227 app.get('/magic', function(req, res){228 res.send(res.partial('magic.jade', {229 as: 'word',230 collection: ['one', 'two', 'three']231 }));232 });233 234 assert.response(app,235 { url: '/magic' },236 { body: '<li class="first">one</li><li class="word-1">two</li><li class="last">three</li>' });Added test for non-collection partial supportTj Holowaychukbefore adoption5842a3b
lines 237–238why, one step back237 238 // Non-collection supportAdded support for "as" for non-collection partials. Closes #341Tj Holowaychukbefore adoption8db1138
lines 239–241why, one step back239 app.get('/movie', function(req, res){240 res.send(res.partial('movie.jade', {241 object: movies[0]Added test for non-collection partial supportTj Holowaychukbefore adoption5842a3b
lines 242–245why, one step back242 }));243 });244 245 assert.response(app,Added support for "as" for non-collection partials. Closes #341Tj Holowaychukbefore adoption8db1138
lines 246–258why, one step back246 { url: '/movie' },247 { body: '<li><div class="title">Nightmare Before Christmas</div><div class="director">Tim Burton</div></li>' });248 249 app.get('/video-global', function(req, res){250 res.send(res.partial('video.jade', {251 object: movies[0],252 as: global253 })); 254 });255 256 // Non-collection as: global257 assert.response(app,258 { url: '/video-global' },Added test for non-collection partial supportTj Holowaychukbefore adoption5842a3b
line 259why, one step back259 { body: '<p>Tim Burton</p>' });Added support for "as" for non-collection partials. Closes #341Tj Holowaychukbefore adoption8db1138
lines 260–263why, one step back260261 app.get('/person-this', function(req, res){262 res.send(res.partial('person.jade', {263 object: { name: 'tj' },Added partial tests for collection locals + passed localsTj Holowaychukbefore adoptionf86f1e8
line 264why, one step back264 locals: { label: 'User:' },Added support for "as" for non-collection partials. Closes #341Tj Holowaychukbefore adoption8db1138
lines 265–271why, one step back265 as: this266 })); 267 });268 269 // Non-collection as: this270 assert.response(app,271 { url: '/person-this' },Added partial tests for collection locals + passed localsTj Holowaychukbefore adoptionf86f1e8
lines 272–281why, one step back272 { body: '<p>User: tj</p>' });273 274 // No options275 app.get('/nothing', function(req, res){276 res.send(res.partial('hello.ejs'));277 });278 279 assert.response(app,280 { url: '/nothing' },281 { body: 'Hello' });Merge branch 'params' into connectTj Holowaychukbefore adoption9449c4b
lines 282–283why, one step back282 }283};