Try this article: Socket.IO and Asynchronous Testing with node.js.
So let the fake. I mean, let them create fake instances of the rival servers, as well as the render client. Then we build a test suite that uses these fakes to test the actual server we are developing. I will put some simplified code snippets here for example. If you are really interested in this, you will find it all on Github .
edit: if you need to test functionality for which there is no immediate output, Jasmine BDD provides spies . They can be used to "look inside" the function and check whether certain parameters are passed, etc., and are useful for mocking asynchronous calls for testing, as well as for writing more functional tests:
Jasmine spies are double exams that can act as stubs, spies, fakes or when used in a lawsuit, scoffs ... Spies can be checked if they were or not, and what calling parameters were. The spy has the following fields: wasCalled, callCount, mostRecentCall and argsForCall (see documents). Spies break at the end of each specification.
Docs , article and related SO question .
Andy
source share