robtaussig / react-use-websocket

React Hook for WebSocket communication
MIT License
1.63k stars 135 forks source link

Add an option to skip isWebSocket check #139

Closed zerofirework closed 2 years ago

zerofirework commented 2 years ago

Hi dev team,

I'm writing cypress tests that mock websocket messages. I'm using mock-socket library that creates a mock type of web socket instance. It conflicts with the assertIsWebSocket function in the react-use-websocket because it is not an instance of the native WebSocket.

Can we add a new option to skip this check? For example:

const { sendMessage, lastMessage, readyState } = useWebSocket(socketUrl, {
  skipAssert: true
});
robtaussig commented 2 years ago

Thank you @zerofirework,

Will do!

robtaussig commented 2 years ago

Hi @zerofirework

Updated to 4.1.3.

Thanks for the suggestion!

https://github.com/robtaussig/react-use-websocket/commit/e7c10efb315a4802896790d8e5a437a4f58466c9

zerofirework commented 2 years ago

Thanks for the quick implementation!

zerofirework commented 2 years ago

BTW, is there any chance that this change can be ported back to 3.0.0?

Yama-Tomo commented 2 years ago

@robtaussig I would like to see this feature ported to 3.0.0 as well!