cover all

This commit is contained in:
harttle
2017-08-14 22:43:49 +08:00
parent 72597c52e5
commit 6d59f34fc8
2 changed files with 38 additions and 44 deletions
+21 -15
View File
@@ -1,5 +1,7 @@
const chai = require('chai')
const expect = chai.expect
// const error = require('../../src/util/error.js')
// const TokenizationError = error.TokenizationError
const mock = require('mock-fs')
chai.use(require('chai-as-promised'))
@@ -64,6 +66,19 @@ describe('error', function () {
expect(err.stack).to.contain('at Object.parse')
})
})
describe('captureStackTrace compatibility', function () {
var captureStackTrace = Error.captureStackTrace
before(() => (Error.captureStackTrace = null))
after(() => (Error.captureStackTrace = captureStackTrace))
it('should use empty string if captureStackTrace not defined', function () {
return expect(engine.parseAndRender('{% . a %}')).to.eventually
.be.rejected
.then(function (err) {
expect(err.stack).to.contain('illegal tag syntax')
expect(err.stack).to.not.contain('at Object.parse')
})
})
})
it('should contain file path in err.file', function () {
var html = '<html>\n<head>\n\n{% . a %}\n\n'
mock({
@@ -145,7 +160,7 @@ describe('error', function () {
' 5| 5th',
' 6| 6th',
' 7| 7th',
'Error: intended render error'
'RenderError: intended render error'
]
return expect(engine.parseAndRender(html.join('\n'))).to.eventually
.be.rejected
@@ -175,7 +190,7 @@ describe('error', function () {
' 5| 5th',
' 6| {%block%}{%endblock%}',
' 7| 7th',
'Error: intended render error'
'RenderError: intended render error'
]
return expect(engine.parseAndRender(html)).to.eventually
.be.rejected
@@ -200,7 +215,7 @@ describe('error', function () {
' 5| 5th',
' 6| 6th',
' 7| 7th',
'Error: intended render error'
'RenderError: intended render error'
]
return expect(engine.parseAndRender(html)).to.eventually
.be.rejected
@@ -314,7 +329,7 @@ describe('error', function () {
' 5| 5th',
' 6| 6th',
' 7| 7th',
'AssertionError: tag a not found'
'ParseError: tag a not found'
]
return expect(engine.parseAndRender(html.join('\n'))).to.eventually
.be.rejected
@@ -332,7 +347,7 @@ describe('error', function () {
'>> 2| X{% a %} {% enda %} Y',
' 3| 3rd',
' 4| 4th',
'AssertionError: tag a not found'
'ParseError: tag a not found'
]
return expect(engine.parseAndRender(html.join('\n'))).to.eventually
.be.rejected
@@ -342,15 +357,6 @@ describe('error', function () {
})
})
it('should contain the whole template content in err.input', function () {
var html = 'bar\nfoo{% a %}\nfoo'
return expect(engine.parseAndRender(html)).to.eventually
.be.rejected
.then(function (err) {
expect(err.input).to.equal(html)
})
})
it('should contain line number in err.line', function () {
var html = '<html>\n<head>\n\n{% raw %}\n\n'
return expect(engine.parseAndRender(html)).to.eventually
@@ -364,7 +370,7 @@ describe('error', function () {
return expect(engine.parseAndRender('{% -a %}')).to.eventually
.be.rejected
.then(function (err) {
expect(err.stack).to.contain('AssertionError: tag -a not found')
expect(err.stack).to.contain('ParseError: tag -a not found')
expect(err.stack).to.match(/at .*:\d+:\d+\)/)
})
})