Skip to content
Myr

tests: add more app.render tests

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent dcecdc9 · Browse files · 1 file+115 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+115 added−0 removed

  • tests:+115 added−0 removed

1 file+115 added−0 removed

modified:test/app.render.js+115 added
52 unmodified lines
53 done();54 })55 })5657 it('should handle render error throws', function(done){58 var app = express();5960 function View(name, options){61 this.name = name;62 this.path = 'fale';63 }6465 View.prototype.render = function(options, fn){66 throw new Error('err!');67 };6869 app.set('view', View);7071 app.render('something', function(err, str){72 err.should.be.ok;73 err.message.should.equal('err!');74 done();75 })76 })7778 describe('when the file does not exist', function(){79 it('should provide a helpful error', function(done){80 var app = express();81 app.set('views', __dirname + '/fixtures');
70 unmodified lines
152 done();153 })154 })155 })156157 describe('caching', function(){158 it('should always lookup view without cache', function(done){159 var app = express();160 var count = 0;161162 function View(name, options){163 this.name = name;164 this.path = 'fake';165 count++;166 }167168 View.prototype.render = function(options, fn){169 fn(null, 'abstract engine');170 };171172 app.set('view cache', false);173 app.set('view', View);174175 app.render('something', function(err, str){176 if (err) return done(err);177 count.should.equal(1);178 str.should.equal('abstract engine');179 app.render('something', function(err, str){180 if (err) return done(err);181 count.should.equal(2);182 str.should.equal('abstract engine');183 done();184 })185 })186 })187188 it('should cache with "view cache" setting', function(done){189 var app = express();190 var count = 0;191192 function View(name, options){193 this.name = name;194 this.path = 'fake';195 count++;196 }197198 View.prototype.render = function(options, fn){199 fn(null, 'abstract engine');200 };201202 app.set('view cache', true);203 app.set('view', View);204205 app.render('something', function(err, str){206 if (err) return done(err);207 count.should.equal(1);208 str.should.equal('abstract engine');209 app.render('something', function(err, str){210 if (err) return done(err);211 count.should.equal(1);212 str.should.equal('abstract engine');213 done();214 })215 })216 })217 })218 })219220 describe('.render(name, options, fn)', function(){221 it('should render the template', function(done){
35 unmodified lines
257 str.should.equal('<p>jane</p>');258 done();259 })260 })261262 describe('caching', function(){263 it('should cache with cache option', function(done){264 var app = express();265 var count = 0;266267 function View(name, options){268 this.name = name;269 this.path = 'fake';270 count++;271 }272273 View.prototype.render = function(options, fn){274 fn(null, 'abstract engine');275 };276277 app.set('view cache', false);278 app.set('view', View);279280 app.render('something', {cache: true}, function(err, str){281 if (err) return done(err);282 count.should.equal(1);283 str.should.equal('abstract engine');284 app.render('something', {cache: true}, function(err, str){285 if (err) return done(err);286 count.should.equal(1);287 str.should.equal('abstract engine');288 done();289 })290 })291 })292 })293 })294})