Skip to content

Add tests for disconnect using connect argument #271

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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