jeudi 19 septembre 2019

How to test GraphQL subscriptions that do not return anything with React?

We're using a react app that accesses its data through graphql queries and subscriptions. We use the subscribeToMore mechanism for that. That all works fine. We use tests where we use the MockedProvider from @apollo/react-testing. This also works fine if the query returns a value and the subscription also returns a valid object. Now we want to test the case where the query returned something and the subscription was startet but didn't get any data, yet. Using result: {} actually works, but also write something to console.error.

console.error node_modules/@testing-library/react/dist/act-compat.js:50
Unhandled GraphQL subscription error TypeError: Cannot read property 'subscribeDeviceStateSummary' of undefined
    at /Users/consort/Documents/projects/building-insights-workspace/building-insights/node_modules/apollo-cache-inmemory/lib/bundle.cjs.js:759:27
    at Array.forEach (<anonymous>)

Has anybody got any idea how to test this case?

Aucun commentaire:

Enregistrer un commentaire