I have a simple async callback test that I've set up with mocha:
describe('test', function () {
it('should not work', function(done) {
client.on('success', function () {
return done('client saw success message but should have errored');
});
client.on('error', function (err) {
return done();
});
});
});
The idea is that the client does some async operation and should receive an error event. If it receives anything else, then the test should fail.
Unfortunately, mocha keeps complaining:
done() called multiple times
I've done all sorts of things to verify that this is not true. For example, I've tried throwing an error before the done in the success handler, logging when control reaches the success handler, etc.
How can I get this test to run without telling me I'm calling done twice? I would throw an error instead of calling done with an error message, but that would cause the test to fail with a timeout instead of the error I want.