mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 12:19:51 +01:00
tests: add more app.render tests
This commit is contained in:
parent
dcecdc9be6
commit
392ef1eb06
|
|
@ -54,6 +54,27 @@ describe('app', function(){
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should handle render error throws', function(done){
|
||||||
|
var app = express();
|
||||||
|
|
||||||
|
function View(name, options){
|
||||||
|
this.name = name;
|
||||||
|
this.path = 'fale';
|
||||||
|
}
|
||||||
|
|
||||||
|
View.prototype.render = function(options, fn){
|
||||||
|
throw new Error('err!');
|
||||||
|
};
|
||||||
|
|
||||||
|
app.set('view', View);
|
||||||
|
|
||||||
|
app.render('something', function(err, str){
|
||||||
|
err.should.be.ok;
|
||||||
|
err.message.should.equal('err!');
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('when the file does not exist', function(){
|
describe('when the file does not exist', function(){
|
||||||
it('should provide a helpful error', function(done){
|
it('should provide a helpful error', function(done){
|
||||||
var app = express();
|
var app = express();
|
||||||
|
|
@ -132,6 +153,68 @@ describe('app', function(){
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('caching', function(){
|
||||||
|
it('should always lookup view without cache', function(done){
|
||||||
|
var app = express();
|
||||||
|
var count = 0;
|
||||||
|
|
||||||
|
function View(name, options){
|
||||||
|
this.name = name;
|
||||||
|
this.path = 'fake';
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
View.prototype.render = function(options, fn){
|
||||||
|
fn(null, 'abstract engine');
|
||||||
|
};
|
||||||
|
|
||||||
|
app.set('view cache', false);
|
||||||
|
app.set('view', View);
|
||||||
|
|
||||||
|
app.render('something', function(err, str){
|
||||||
|
if (err) return done(err);
|
||||||
|
count.should.equal(1);
|
||||||
|
str.should.equal('abstract engine');
|
||||||
|
app.render('something', function(err, str){
|
||||||
|
if (err) return done(err);
|
||||||
|
count.should.equal(2);
|
||||||
|
str.should.equal('abstract engine');
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should cache with "view cache" setting', function(done){
|
||||||
|
var app = express();
|
||||||
|
var count = 0;
|
||||||
|
|
||||||
|
function View(name, options){
|
||||||
|
this.name = name;
|
||||||
|
this.path = 'fake';
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
View.prototype.render = function(options, fn){
|
||||||
|
fn(null, 'abstract engine');
|
||||||
|
};
|
||||||
|
|
||||||
|
app.set('view cache', true);
|
||||||
|
app.set('view', View);
|
||||||
|
|
||||||
|
app.render('something', function(err, str){
|
||||||
|
if (err) return done(err);
|
||||||
|
count.should.equal(1);
|
||||||
|
str.should.equal('abstract engine');
|
||||||
|
app.render('something', function(err, str){
|
||||||
|
if (err) return done(err);
|
||||||
|
count.should.equal(1);
|
||||||
|
str.should.equal('abstract engine');
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('.render(name, options, fn)', function(){
|
describe('.render(name, options, fn)', function(){
|
||||||
|
|
@ -175,5 +258,37 @@ describe('app', function(){
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('caching', function(){
|
||||||
|
it('should cache with cache option', function(done){
|
||||||
|
var app = express();
|
||||||
|
var count = 0;
|
||||||
|
|
||||||
|
function View(name, options){
|
||||||
|
this.name = name;
|
||||||
|
this.path = 'fake';
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
View.prototype.render = function(options, fn){
|
||||||
|
fn(null, 'abstract engine');
|
||||||
|
};
|
||||||
|
|
||||||
|
app.set('view cache', false);
|
||||||
|
app.set('view', View);
|
||||||
|
|
||||||
|
app.render('something', {cache: true}, function(err, str){
|
||||||
|
if (err) return done(err);
|
||||||
|
count.should.equal(1);
|
||||||
|
str.should.equal('abstract engine');
|
||||||
|
app.render('something', {cache: true}, function(err, str){
|
||||||
|
if (err) return done(err);
|
||||||
|
count.should.equal(1);
|
||||||
|
str.should.equal('abstract engine');
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user