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
Provenance
- Commit
392ef1e- Tree
73f4319- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
dcecdc9
1 file changed+115 added−0 removed
modified:test/app.render.js+115 added
52 unmodified lines53 done();54 })55 })56 57+ it('should handle render error throws', function(done){58+ var app = express();59+60+ function View(name, options){61+ this.name = name;62+ this.path = 'fale';63+ }64+65+ View.prototype.render = function(options, fn){66+ throw new Error('err!');67+ };68+69+ app.set('view', View);70+71+ app.render('something', function(err, str){72+ err.should.be.ok;73+ err.message.should.equal('err!');74+ done();75+ })76+ })77+78 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 lines152 done();153 })154 })155 })156+157+ describe('caching', function(){158+ it('should always lookup view without cache', function(done){159+ var app = express();160+ var count = 0;161+162+ function View(name, options){163+ this.name = name;164+ this.path = 'fake';165+ count++;166+ }167+168+ View.prototype.render = function(options, fn){169+ fn(null, 'abstract engine');170+ };171+172+ app.set('view cache', false);173+ app.set('view', View);174+175+ 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+ })187+188+ it('should cache with "view cache" setting', function(done){189+ var app = express();190+ var count = 0;191+192+ function View(name, options){193+ this.name = name;194+ this.path = 'fake';195+ count++;196+ }197+198+ View.prototype.render = function(options, fn){199+ fn(null, 'abstract engine');200+ };201+202+ app.set('view cache', true);203+ app.set('view', View);204+205+ 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 })219 220 describe('.render(name, options, fn)', function(){221 it('should render the template', function(done){35 unmodified lines257 str.should.equal('<p>jane</p>');258 done();259 })260 })261+262+ describe('caching', function(){263+ it('should cache with cache option', function(done){264+ var app = express();265+ var count = 0;266+267+ function View(name, options){268+ this.name = name;269+ this.path = 'fake';270+ count++;271+ }272+273+ View.prototype.render = function(options, fn){274+ fn(null, 'abstract engine');275+ };276+277+ app.set('view cache', false);278+ app.set('view', View);279+280+ 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 })