thoov / mock-socket

Javascript mocking library for WebSockets and Socket.IO
MIT License
800 stars 119 forks source link

cannot emit a single array argument #205

Open olareoun opened 6 years ago

olareoun commented 6 years ago

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 })
    })
Chalisi commented 5 years ago

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.