fix nested render error message

This commit is contained in:
harttle
2016-11-16 00:48:54 +08:00
parent 20af0c489e
commit 64e9cb7044
2 changed files with 37 additions and 3 deletions
+33 -3
View File
@@ -10,6 +10,9 @@ var strictEngine = require('../..')({
});
describe('error', function() {
afterEach(function(){
mock.restore();
});
describe('TokenizationError', function() {
it('should throw TokenizationError when tag illegal', function() {
@@ -78,7 +81,9 @@ describe('error', function() {
describe('RenderError', function() {
beforeEach(function() {
engine = require('../..')();
engine = require('../..')({
root: '/'
});
engine.registerTag('throwingTag', {
render: function() {
throw new Error('intended render error');
@@ -131,7 +136,7 @@ describe('error', function() {
expect(e.message).to.contain('undefined variable: a');
});
});
it('should contain template content in err.message', function() {
it('should contain template context in err.stack', function() {
var html = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th'];
var message = [
' 2| 2nd',
@@ -150,6 +155,31 @@ describe('error', function() {
expect(err.name).to.equal('RenderError');
});
});
it.only('should contain original template context in err.stack', function() {
var origin = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th'];
mock({
'/throwing-tag.html': origin.join('\n')
});
var html = '{%include "throwing-tag.html"%}';
var message = [
' 2| 2nd',
' 3| 3rd',
'>> 4| X{%throwingTag%} Y',
' 5| 5th',
' 6| 6th',
' 7| 7th',
'Error: intended render error',
];
return expect(engine.parseAndRender(html)).to.eventually
.be.rejected
.then(function(err) {
console.log(err.message);
console.log(err.stack);
expect(err.message).to.equal('intended render error, line:4');
expect(err.stack).to.contain(message.join('\n'));
expect(err.name).to.equal('RenderError');
});
});
it('should contain the whole template content in err.input', function() {
var html = 'bar\nfoo{%throwingTag%}\nfoo';
return expect(engine.parseAndRender(html)).to.eventually
@@ -245,7 +275,7 @@ describe('error', function() {
});
});
it('should contain template content in err.message', function() {
it('should contain template context in err.stack', function() {
var html = ['1st', '2nd', '3rd', 'X{% a %} {% enda %} Y', '5th', '6th', '7th'];
var message = [
' 2| 2nd',