I'm working on a nodejs application. I managed to break some of the code in separate modules, that I'm testing using nodeunit, but a substantial part of my code base still relies on socket.io.
How can I test my socket.io events?
Try this article: Socket.IO and Asynchronous Testing with node.js.
So, let's fake. I mean, let's create fake instances of the contender servers, as well as the visualization client. Then, we'll build a test suite that uses these fakes to test-drive the actual server we're developing. I'll paste some slightly simplified pieces of code here for example. If you are really interested in the stuff, you'll find it all on Github.
edit: if you need to test functionality for which there is no immediate output, Jasmine BDD provides spies. These can be used to "see inside" a function and test whether certain parameters are passed etc, and are useful for mocking asynchronous calls for testing, as well as writing more functional tests:
Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks...Spies can be checked if they were called or not and what the calling params were. A Spy has the following fields: wasCalled, callCount, mostRecentCall, and argsForCall (see docs). Spies are torn down at the end of every spec.
Docs, an article and a related SO question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With