Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options for Engines #3114

Open
wants to merge 2 commits into
base: 5.0
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Added positive and negative tests
  • Loading branch information
Maya committed Oct 27, 2016
commit 6d186f72eb5e6034c961b1f0038269f5a0e7d609
45 changes: 44 additions & 1 deletion test/app.engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function render(path, options, fn) {
}

describe('app', function(){
describe('.engine(ext, fn)', function(){
describe('.engine(ext, fn, options)', function(){
it('should map a template engine', function(done){
var app = express();

Expand Down Expand Up @@ -76,5 +76,48 @@ describe('app', function(){
done();
})
})

it('should throw when no options are specified and the file does not exist', function(done){
var app = express();

app.set('views', __dirname + '/fixtures');
app.engine('.html', render);
app.set('view engine', '.html');

app.render('nonexistent', function(err, str){
if (err) return done();
done(new Error('No Error was thrown despite missing file'));
})
})

it('should throw when noFileSystem is explicitly set to false and the file does not exist', function(done){
var app = express();

app.set('views', __dirname + '/fixtures');
app.engine('.html', render, { noFileSystem: false });
app.set('view engine', '.html');

app.render('nonexistent', function(err, str){
if (err) return done();
done(new Error('No Error was thrown despite missing file'));
})
})

it('should work when noFileSystem is set to true and the file does not exist', function(done){
var app = express();
var fileName = 'nonexistent';

app.set('views', __dirname + '/fixtures');
app.engine('.html', function(name, options, fn) {
name.should.equal(fileName);
done();
}, { noFileSystem: true });
app.set('view engine', '.html');

app.render(fileName, function(err, str){
if (err) return done(err);
done();
})
})
})
})