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.

有帮助吗?

解决方案

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 !'); 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top