Question

I created a wrapper object to interact with the net module. Objects that implement this wrapper can register callbacks to be called when any of the events from net.Server is emitted.

Now I'm trying to test these callbacks and I don't know how to create a fake Socket as it comes from a new connection, to pass it to the callbacks.

Does anyone have any idea on how to do it?

Thank you very much.

Was it helpful?

Solution

I created a mock that implements Node 0.6 net.Socket api, usage:

var dummySocket = new ReadWriteNetStream();

// Debug
dummySocket.on('data', function(data){
console.log('write received', data);
});

dummySocket.write('hey !'); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top