Skip to content

Conversation

@Eric162
Copy link

@Eric162 Eric162 commented May 9, 2025

In the README, it states that since version 2.0.0, you can disconnect from the socket using the connect (third) argument of the hook, but there doesn't seem to be a test for it.

Components can close/unsubscribe from a WebSocket by passing false as the third parameter. This provides a more explicit solution than the previous method of setting the socketUrl to null. Both methods work and are supported usage.

This PR adds a test so nobody else has to investigate whether it's the library's code or their own which isn't working 😅 (spoiler it was my own code).

A few points of note:

  • The ReadyState.CONNECTING on the reconnect is happening, but in the tests it happens to fast to read the state out and assert on it.
  • Ideally the WS mock from jest-mock-websocket could tell us how many connections there are (is that just 0 or 1 ?), but alas it cannot. So using some mocks of the events to validate that we have connected and disconnected the right amount of times.

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

Successfully merging this pull request may close these issues.

1 participant