Testing Apollo Client subscriptions

Viewed 1555

I recently added support for subscriptions via WebSockets to my React+Redux+ApolloGraphQL application. Since doing that I cannot run my unit tests anymore.

The problem I come up with is:

Unable to find native implementation, or alternative implementation for WebSocket!

It seems there is not an available implementation for WebSockets on the node environment where I run my tests.

There are a couple of proposed solutions in this bug report that involve using the 'ws' library for node but I cannot make them work. Either I cannot load the library properly, or I can but then the application doesn't work.

I was thinking of a way to load the library depending on the environment I'm on but:

  1. I don't know how to do that
  2. I don't know if it's the right approach.

Any suggestions?

1 Answers
Related