Skip to content

Commit

Permalink
tests: add tests for handling helper errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Sep 27, 2019
1 parent c3826ee commit 2f12c5e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/3.x/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ var assert = require('assert');
// local
var hbs = require('../../').create();

hbs.registerHelper('make_error', function () {
throw new TypeError('oops!')
})

hbs.registerHelper('link_to', function(context) {
return "<a href='" + context.url + "'>" + context.body + "</a>";
});
Expand Down Expand Up @@ -139,6 +143,10 @@ before(function () {
})
})

app.get('/helper-error', function (req, res) {
res.render('error')
})

app.get('/syntax-error', function (req, res) {
res.render('syntax-error', {
cache: true
Expand Down Expand Up @@ -192,6 +200,14 @@ test('partials', function(done) {
.end(done)
});

test('helper error', function (done) {
request(app)
.get('/helper-error')
.expect(500)
.expect(shouldHaveFirstLineEqual('TypeError: ' + path.join(__dirname, 'views', 'error.hbs') + ': oops!'))
.end(done)
})

test('html extension', function(done) {
request(app)
.get('/html')
Expand Down
1 change: 1 addition & 0 deletions test/3.x/views/error.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
running {{{make_error}}}
16 changes: 16 additions & 0 deletions test/4.x/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ var assert = require('assert');
// local
var hbs = require('../../').create();

hbs.registerHelper('make_error', function () {
throw new TypeError('oops!')
})

hbs.registerHelper('link_to', function(context) {
return "<a href='" + context.url + "'>" + context.body + "</a>";
});
Expand Down Expand Up @@ -138,6 +142,10 @@ before(function () {
})
})

app.get('/helper-error', function (req, res) {
res.render('error')
})

app.get('/syntax-error', function (req, res) {
res.render('syntax-error', {
cache: true
Expand Down Expand Up @@ -199,6 +207,14 @@ test('index', function(done) {
.end(done)
});

test('helper error', function (done) {
request(app)
.get('/helper-error')
.expect(500)
.expect(shouldHaveFirstLineEqual('TypeError: ' + path.join(__dirname, 'views', 'error.hbs') + ': oops!'))
.end(done)
})

test('partials', function(done) {
request(app)
.get('/partials')
Expand Down
1 change: 1 addition & 0 deletions test/4.x/views/error.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
running {{{make_error}}}

0 comments on commit 2f12c5e

Please sign in to comment.