-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better way of testing asynchronous code? #110
Comments
Use promises and mocha as promised? |
I would use sinon's fake timers. |
Thanks, for the hints. Promises looks, well, promising. :) But I think in this cases fake timers suit really well, I'll give them a try. I still hope though, there is going to be a way built into Mocha to fo asynchronous stuff more cleanly... But I guess it's a Mocha rather then Konacha issue? Or can something be done in Konacha? Otherwise I guess we shall close this? |
I extend mocha (the test runner) with the mocha-as-promised lib (also found in the konacha-chai-matchers gem) and test these things using All solutions work really well, but I prefer to write all async code as promises :-) |
Yeah, this is a need that 3rd party tools (promises or fake timers) solve pretty well without needing coordination from the testing framework. You could raise it with mocha, but I suspect you'll likely get a similar response there. |
in the event that you have an app that relies on a deferred block of code: |
This works, but is rather ugly because of the try catch block:
Is there a better way of doing this? Also, the message when the test fails is not very pretty:
Related is this mocha pull request I think: mochajs/mocha#278
The text was updated successfully, but these errors were encountered: