I wrote a TCP server using Node.js and on my tests (with Mocha) I'm testing that the server actually emits all the events it should. The one problem that I'm finding is that I cannot trigger the error event at will so I cannot automate this test.
socket.on('error', function()
{
// How do I test this?
});
Is there a way to trigger this event manually? O maybe craft a corrupt packet?
You can emit it manually: socket.emit('error', new Error('foo bar baz'));
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