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.

Était-ce utile?

La 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 !'); 
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top