Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emitting with object as payload converts the object to a string #297

Open
gCardinal opened this issue Apr 3, 2020 · 1 comment
Open

Comments

@gCardinal
Copy link

In a test, if I call server.emit('an-event', {foo: 'bar'}), the socket in my test will receive [Object object] as the payload. The exact code is below.

I am using the Socket.IO implementation and it allows objects to be given as arguments to emit() as can be seen here. I would assume this library should also respect that.


it(`dispatches setCurrentPlayer() when Events.ChangeCurrentPlayer event is received`, () => {
    const currentPlayer: Player = { id: '1', color: 'red' }
    const playerList: Player[] = [currentPlayer, { id: '2', color: 'blue' }]

    const server = new Server(configuration.server.uri)
    const store = createMockedStore({}, SocketIO)
    store.dispatch(joinAction)
    const action = switchCurrentPlayer(currentPlayer, playerList)
    server.emit(Events.ChangeCurrentPlayer, action.payload) // This is the relevant bit

    // Next line will fail, error after this. 
    expect(store.getActions()).toContainObject(setCurrentPlayer(action.payload))
})

Notice the object with type: setCurrentPlayer in the expected and received.

Error: expected [{"payload": {"player": {"id": "0987"}, "settings": {"gameNumber": "1234"}}, "type": "JOIN_GAME_SUCCESS"}, {"meta": {"dispatchedByWsMiddleware": true}, "payload": "[object Object]", "type": "setCurrentPlayer"}] to contain object {"payload": {"color": "blue", "id": "2"}, "type": "setCurrentPlayer"}
@gCardinal
Copy link
Author

Potentially fixed by #286.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant