Rejecting promise when parsing fails

This commit is contained in:
Jeff Avallone 2014-12-20 10:47:41 -05:00
parent 6c5b36f334
commit ccdb29224a
2 changed files with 18 additions and 4 deletions

View File

@ -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() {

View File

@ -16,10 +16,15 @@ export default class Parser {
var deferred = Q.defer();
setTimeout(() => {
try {
javascript.Parser.SyntaxNode.state = this.state;
this.parsed = javascript.parse(expression.replace(/\n/g, '\\n'));
deferred.resolve(this);
}
catch(e) {
deferred.reject(e);
}
});
return deferred.promise;