Skip to content

Commit 2f12c5e

Browse files
committed
tests: add tests for handling helper errors
1 parent c3826ee commit 2f12c5e

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

test/3.x/app.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ var assert = require('assert');
1111
// local
1212
var hbs = require('../../').create();
1313

14+
hbs.registerHelper('make_error', function () {
15+
throw new TypeError('oops!')
16+
})
17+
1418
hbs.registerHelper('link_to', function(context) {
1519
return "<a href='" + context.url + "'>" + context.body + "</a>";
1620
});
@@ -139,6 +143,10 @@ before(function () {
139143
})
140144
})
141145

146+
app.get('/helper-error', function (req, res) {
147+
res.render('error')
148+
})
149+
142150
app.get('/syntax-error', function (req, res) {
143151
res.render('syntax-error', {
144152
cache: true
@@ -192,6 +200,14 @@ test('partials', function(done) {
192200
.end(done)
193201
});
194202

203+
test('helper error', function (done) {
204+
request(app)
205+
.get('/helper-error')
206+
.expect(500)
207+
.expect(shouldHaveFirstLineEqual('TypeError: ' + path.join(__dirname, 'views', 'error.hbs') + ': oops!'))
208+
.end(done)
209+
})
210+
195211
test('html extension', function(done) {
196212
request(app)
197213
.get('/html')

test/3.x/views/error.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
running {{{make_error}}}

test/4.x/app.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ var assert = require('assert');
1111
// local
1212
var hbs = require('../../').create();
1313

14+
hbs.registerHelper('make_error', function () {
15+
throw new TypeError('oops!')
16+
})
17+
1418
hbs.registerHelper('link_to', function(context) {
1519
return "<a href='" + context.url + "'>" + context.body + "</a>";
1620
});
@@ -138,6 +142,10 @@ before(function () {
138142
})
139143
})
140144

145+
app.get('/helper-error', function (req, res) {
146+
res.render('error')
147+
})
148+
141149
app.get('/syntax-error', function (req, res) {
142150
res.render('syntax-error', {
143151
cache: true
@@ -199,6 +207,14 @@ test('index', function(done) {
199207
.end(done)
200208
});
201209

210+
test('helper error', function (done) {
211+
request(app)
212+
.get('/helper-error')
213+
.expect(500)
214+
.expect(shouldHaveFirstLineEqual('TypeError: ' + path.join(__dirname, 'views', 'error.hbs') + ': oops!'))
215+
.end(done)
216+
})
217+
202218
test('partials', function(done) {
203219
request(app)
204220
.get('/partials')

test/4.x/views/error.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
running {{{make_error}}}

0 commit comments

Comments
 (0)