In the following script only one test is passing. Testing error (throw Error()) is failing with message 1) a test should throw error:
var expect = require('chai').expect;
describe("a test", function() {
var fn;
before(function() {
fn = function(arg){
if(arg == 'error'){
throw new Error();
}else{
return 'hi';
}
}
});
it("should throw error", function() {
expect(fn('error')).to.throw(Error);
});
it("should return hi", function() {
expect(fn('hi')).to.equal('hi');
});
});
How to alter expect to test errors?