I'm testing an angular.js
app using karma
with sinon-chai
. I need to test a code like this:
var sync = function() {
async.then(function() {
// success
}, function() {
throw Error('foo');
});
}
sync
is the function I want to test. async
is a function returning a $q
promise I want to test it fails throwing an error.
My ideal test suit:
describe('unit', function() {
it('should throw an error', function() {
expect(function() {
return sync();
}).to.throw(Error, 'foo');
})
});
But, it fails at afterEach()
because the error is thrown on $digest
.
How can I achieve this test?
Thank you very much!