Emit function parameters (Client and Server) do not mirror Socket.io API
See original GitHub issueHi @thoov,
I have been using your library at work for unit testing a Socket.io based application we are making. I have contributed to the library in Issue #79 in order to add some missing functionality we needed in our app.
When running tests I am running into an issue were the API for mock-socket’s emit function is not aligned with Socket.io’s emit function.
The Socket.io API for emit is emit(event, ...data)
, which allows for variable amounts of data args to be passed to the callback function listening to the specified event name.
The mock-socket API for emit is emit(event, data, options)
for the server and emit(event, data)
for the client. The mock-socket API does not allow for variable amounts of data args to be passed. We could pass all of our data as an object, but I feel this incorrect.
I looked into making the changes necessary to correct this but it would be a major change to libraries API. I would be willing to do the work to make the modifications to align the API between the two libraries. Before doing this work I wanted first to talk to you about why the API was structured this way and your ideas on how to correct it.
Thanks!
Issue Analytics
- State:
- Created 7 years ago
- Comments:16 (7 by maintainers)
@thoov Congrats on getting married!! It’s a crazy and fun day 😃
Okay based on your example you are only printing the first argument. To access all the data being returned by the emit callback in your example you would have to do the following:
Following are code examples to see this in action:
client.js
server.js
The above console logs the following from the server
Thanks! Let me know if you need anything else from me!
@rocketedaway Sorry for the delay. I just got married so its been crazy the last couple of weeks with that.
I ran the example code that you provided and was able to see the same results as you pointed out. However, I created this example:
index.html
server.js
On both the server and client I just see ‘foo’ which it appears socket.io is just taking the first argument. This is what mock-socket is currently doing. Do you have an example using pure socket.io where multiple arguments are passed? (I tested against the latest 1.4.5)