1

I am trying to add a stub to mock flutter-graphql watchQuery results to in a unit test but it seems complex because watchQuery returns an ObservableQuery which depends on QueryManager.

ObservableQuery watchQuery(WatchQueryOptions options) {
    options.policies =
        defaultPolicies.watchQuery.withOverrides(options.policies);
    return queryManager.watchQuery(options);
  }

Can someone provide an example for a watchQuery stub?

  • Any luck on this @Asmaa? – WiFi Feb 07 '22 at 18:58
  • @WiFi yeah, we used mockito's `@GenerateMocks([ObservableQuery])` to mock it. and then the stub would look something like this: `when(yourGraphqlClient.watchQuery(any)).thenAnswer((_) async => yourMockObservableQueryObject);` – Asmaa Amrawy Feb 08 '22 at 12:57

0 Answers0