Skip to content
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

Do not know how I can mock my RTK websocket with this lib #129

Open
kasir-barati opened this issue Dec 4, 2023 · 1 comment
Open

Do not know how I can mock my RTK websocket with this lib #129

kasir-barati opened this issue Dec 4, 2023 · 1 comment

Comments

@kasir-barati
Copy link

kasir-barati commented Dec 4, 2023

Hi dear reader

I was looking at this lib and could not find any clue on how you should mock your WebSocket when you are using a library like Redux and SocketIO. Let's say you have a RTK query like this:

endpoints: (build) => ({
  someSubscription: build.query<ResponseSchema[], void>({
    queryFn: async () => {
      return { data: null }
    },
    async onCacheEntryAdded(_, { updateCachedData, cacheDataLoaded, cacheEntryRemoved }) {
      const socket = io('ws://localhost:3000/', {
        withCredentials: true,
        transports: ['websocket'],
      })
      socket.on("message", () => {/* cache received msg in */})
      socket.close()
    },
  }),
})

How can I mock the cached data? is it even possible to do it with this lib? if not with what I can do that?

@kasir-barati
Copy link
Author

I think we need to leverage and utilise two things at the same time, the first one I think is this addon and the other one might be: https://github.com/thoov/mock-socket

After a few weeks I ended up asking same question and landing back to this page again but not luck still 😭

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

No branches or pull requests

1 participant