Skip to content

Instantly share code, notes, and snippets.

@danahartweg
Created July 3, 2022 21:55
Show Gist options
  • Save danahartweg/e21f39ae57f0bec062373705453efb35 to your computer and use it in GitHub Desktop.
Save danahartweg/e21f39ae57f0bec062373705453efb35 to your computer and use it in GitHub Desktop.
Mutation test harness - Unit testing Flutter GraphQL
MockQueryResult<T> generateMockMutation<T>(MockGraphQLClient graphQLClient) {
registerFallbackValue(_FakeMutationOptions<T>());
final result = MockQueryResult<T>();
when(() => graphQLClient.mutate<T>(any())).thenAnswer((_) async => result);
final queryManager = graphQLClient.queryManager;
when(() => queryManager.mutate<T>(any())).thenAnswer((_) async => result);
return result;
}
class MockQueryResult<T> extends Mock implements QueryResult<T> {}
class _FakeMutationOptions<T> extends Fake implements MutationOptions<T> {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment