Catching thrown errors with SinonJS
问题 I've got a method that may throw an Error, but I'm having trouble writing a SinonJS/Mocha/Should unit test case for this condition. Sample function under test: function testError(value) { if (!value) { throw new Error('No value'); return false; } }; Sample test: describe('#testError', function() { it('throws an error', function() { var spy = sinon.spy(testError); testError(false); spy.threw().should.be.true(); }); }); This outputs: #testError 1) throws an error 0 passing (11ms) 1 failing 1)