Consider a piece of code below:
var expect = require('chai').expect;
parse = function() {
throw {error: 'PROTOCOL_ERROR'}
}
describe('parser', function() {
it('throw error on unfinished command', function() {
try {
parse("*2\r\n$4\r\necho\r\n$11\r\nhel")
} catch (e) {
expect(e).to.equal({error: 'PROTOCOL_ERROR'})
}
})
});
Is there a way to avoid this try...catch
boilerplate in the code? Chai has 'throw' method but it provides only an instanceof
check