mock-socket
mock-socket copied to clipboard
cannot emit a single array argument
This is the situation:
// emit a message with just one argument that is an array
mockServer.emit('surveys', [
{ id: 1, name: 'Survey 1' },
{ id: 2, name: 'Survey 2' },
{ id: 3, name: 'Survey 3' }
])
// it is received as separated args, that is not the desired situation
this.socket.on('surveys', data => { // here data is just { id: 1, name: 'Survey 1' }
this.setState({ surveys: data })
})
Before upgrading to version 8.0.5 It 'worked' by doubling the array
mockServer.emit('surveys', [[
{ id: 1, name: 'Survey 1' },
{ id: 2, name: 'Survey 2' },
{ id: 3, name: 'Survey 3' }
]])
But now with #212 fix, the socket.io emit is broken and it serializes everything to string.