Rejecting promise when parsing fails
This commit is contained in:
parent
6c5b36f334
commit
ccdb29224a
@ -9,7 +9,7 @@ describe('parser/javascript.js', function() {
|
||||
this.parser = new Parser();
|
||||
});
|
||||
|
||||
describe('#parser', function() {
|
||||
describe('#parse', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
spyOn(regexpParser, 'parse');
|
||||
@ -42,6 +42,15 @@ describe('parser/javascript.js', function() {
|
||||
.done();
|
||||
});
|
||||
|
||||
it('rejects the returned promise with the exception thrown', function(done) {
|
||||
this.parser.parse('/example')
|
||||
.then(null, result => {
|
||||
expect(result).toBeDefined();
|
||||
})
|
||||
.finally(done)
|
||||
.done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#render', function() {
|
||||
|
@ -16,10 +16,15 @@ export default class Parser {
|
||||
var deferred = Q.defer();
|
||||
|
||||
setTimeout(() => {
|
||||
javascript.Parser.SyntaxNode.state = this.state;
|
||||
try {
|
||||
javascript.Parser.SyntaxNode.state = this.state;
|
||||
|
||||
this.parsed = javascript.parse(expression.replace(/\n/g, '\\n'));
|
||||
deferred.resolve(this);
|
||||
this.parsed = javascript.parse(expression.replace(/\n/g, '\\n'));
|
||||
deferred.resolve(this);
|
||||
}
|
||||
catch(e) {
|
||||
deferred.reject(e);
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
|
Loading…
Reference in New Issue
Block a user