cube-js/cube

How to mock messages using @cubejs-client/react with websocket transport?

Open

#2.146 geöffnet am 18. Feb. 2021

Auf GitHub ansehen
 (4 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Rust (1.965 Forks)batch import
client:reacthelp wanted

Repository-Metriken

Stars
 (19.563 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 5T 16h) (138 gemergte PRs in 30 T)

Beschreibung

Problem

I am using @cubejs-client/react with @cubejs-client/ws-transport and I'm running into some blockers trying to mock anything.

I use msw for mocking all my "normal" network requests for use in unit testing, integration tests, storybook and a fully mocked dev environment.

I've been searching for a way to mock CubeJS websocket messages in a similar way, but haven't found anything :(

I tried setting up mock-socket and jest-mock-socket but that didn't seem to work for CubeJS?

Do you have any solution in place for mocking CubeJS responses? Ideally I'm looking for something that works like this:

received queryA
respond with resultA

received queryB
respond with resultB

Something like the MockedProvider that apollo has for their ApolloClient. But for @cubejs-client/react

I need a solution that will work in basically any environment: test, local dev, cypress & storybook.

I considered writing a mock for the useCubeQuery hook, but that seems like a slippery slope to go down that road and end up testing implementation details that might break in future versions.

Are there any official mocking/ testing solutions for the frontend clients?

Contributor Guide