@house-agency/brewtils
Version:
The Brewery Node.js Utilities (brewtils)
52 lines (47 loc) • 1.44 kB
JavaScript
const def = require('../catch-default');
const expect = require('chai').expect;
const q = require('q');
describe('Catch default', () => {
it('shall catch an error by string', done => {
q.try(() => {
throw new Error('Some message');
})
.catch(def('Some message', error => {
expect(error.message).to.equal('Some message');
throw new Error('Some other message');
}))
.catch(def('Some message', () => {
throw new Error('This error shall not be catched');
}))
.catch(error => {
expect(error.message).to.equal('Some other message');
})
.done(done);
});
it('shall catch an error by function', done => {
q.try(() => {
throw new Error('Some message');
})
.catch(def(
error => {
return error.message === 'Some message';
},
error => {
expect(error.message).to.equal('Some message');
throw new Error('Some other message');
}
))
.catch(def(
() => {
return false;
},
() => {
throw new Error('This error shall not be catched');
}
))
.catch(error => {
expect(error.message).to.equal('Some other message');
})
.done(done);
});
});