Created
July 3, 2022 22:00
-
-
Save danahartweg/a9245cc46fef9256ce1faf0094f445ad to your computer and use it in GitHub Desktop.
Watch query test harness - Unit testing Flutter GraphQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MockQueryResult<T> generateMockWatchQuery<T>(MockGraphQLClient graphQLClient) { | |
registerFallbackValue(_FakeWatchQueryOptions<T>()); | |
final query = MockObservableQuery<T>(); | |
final result = MockQueryResult<T>(); | |
when(query.close).thenReturn(QueryLifecycle.closed); | |
when(() => query.stream).thenAnswer((_) => Stream.value(result)); | |
when(() => query.latestResult).thenReturn(result); | |
when( | |
() => query.onData( | |
any(), | |
removeAfterInvocation: any(named: 'removeAfterInvocation'), | |
), | |
).thenReturn(() {}); | |
when(() => graphQLClient.watchQuery<T>(any())).thenReturn(query); | |
final queryManager = graphQLClient.queryManager; | |
when(() => queryManager.watchQuery<T>(any())).thenReturn(query); | |
return result; | |
} | |
class MockQueryResult<T> extends Mock implements QueryResult<T> {} | |
class _FakeWatchQueryOptions<T> extends Fake implements WatchQueryOptions<T> {} | |
class MockObservableQuery<T> extends Mock implements ObservableQuery<T> {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment