Testing for an Asynchronous throw in Mocha
问题 I have a block of code that tries to reconnect to Redis if a connection breaks. If it can not re-establish connection, it throws an error. I am trying to test the block of code that throws the error, but I am unable to write a successful test using mocha and chai. My test looks like this: it('throws an error when a connection can\'t be established', function (done) { var c = redisClient.newClient(); c.end(); sinon.stub(redisClient, 'newClient', function () { return { connected: false }; });