Skip to content

Commit 057e7b3

Browse files
committedMar 4, 2019
Add test for line/column info in user-function exception
1 parent bcf38f3 commit 057e7b3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
 

‎tests/compiler.js

+23
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,29 @@
822822
done();
823823
});
824824
});
825+
826+
it('should include error line when exception raised in user function', function(done) {
827+
var tmplStr = [
828+
'{% block content %}',
829+
'<div>{{ foo() }}</div>',
830+
'{% endblock %}',
831+
].join('\n');
832+
var env = new Environment(new Loader('tests/templates'));
833+
var tmpl = new Template(tmplStr, env, 'user-error.njk');
834+
835+
function foo() {
836+
throw new Error('ERROR');
837+
}
838+
839+
tmpl.render({foo: foo}, function(err, res) {
840+
expect(res).to.be(undefined);
841+
expect(err.toString()).to.be([
842+
'Template render error: (user-error.njk) [Line 1, Column 11]',
843+
' Error: ERROR',
844+
].join('\n'));
845+
done();
846+
});
847+
});
825848
}
826849

827850
it('should compile string concatenations with tilde', function(done) {

0 commit comments

Comments
 (0)
Please sign in to comment.