Mocha / Chai expect.to.throw não capturando erros lançados
Estou tendo problemas para conseguir o Chaiexpect.to.throw
para trabalhar em um teste para meu aplicativo node.js. O teste continua falhando com o erro gerado, mas se eu envolver o caso de teste na tentativa de capturar e afirmar o erro detectado, ele funcionará.
Fazexpect.to.throw
não funciona como eu acho que deveria ou algo assim?
it('should throw an error if you try to get an undefined property', function (done) {
var params = { a: 'test', b: 'test', c: 'test' };
var model = new TestModel(MOCK_REQUEST, params);
// neither of these work
expect(model.get('z')).to.throw('Property does not exist in model schema.');
expect(model.get('z')).to.throw(new Error('Property does not exist in model schema.'));
// this works
try {
model.get('z');
}
catch(err) {
expect(err).to.eql(new Error('Property does not exist in model schema.'));
}
done();
});
A falha:
19 passing (25ms)
1 failing
1) Model Base should throw an error if you try to get an undefined property:
Error: Property does not exist in model schema.