Closed JErazo7 closed 2 years ago
Describe the bug
If a data type is specified to a variable that receives the mocked response, an exception is thrown with the following message: type 'Null' is not a subtype of type .....
type 'Null' is not a subtype of type .....
Example:
when(() => graphQLClient.watchQuery(any()), ).thenReturn(MockObservableQuery());
This works:
final _rewardsMembershipQuery = graphQLClient.watchQuery();
This does not work:
ObservableQuery _rewardsMembershipQuery = graphQLClient.watchQuery();
To Reproduce Steps to reproduce the behavior:
test/mocktail_test.dart
import 'package:bloc_test/bloc_test.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:graphql/client.dart'; import 'package:mocktail/mocktail.dart'; import 'rewards_membership_summary_query.ast.gql.dart' as rewards_membership_summary_query; class SomeCubit extends Cubit<int> { final GraphQLClient client; late final ObservableQuery _rewardsMembershipQuery; SomeCubit(this.client) : super(0); void doSomething() { _rewardsMembershipQuery = client.watchQuery( WatchQueryOptions( operationName: 'RewardsMembershipSummary', document: rewards_membership_summary_query.document, fetchPolicy: FetchPolicy.noCache, fetchResults: true, ), ); emit(1); } } class MockGraphQLClient extends Mock implements GraphQLClient {} class MockObservableQuery extends Mock implements ObservableQuery {} class MockWatchQueryOptions extends Mock implements WatchQueryOptions {} void main() { late MockGraphQLClient graphQLClient; final rewardsObservableQuery = MockObservableQuery(); setUp(() { graphQLClient = MockGraphQLClient(); registerFallbackValue(MockWatchQueryOptions()); }); blocTest<SomeCubit, int>( 'initial state is RewardsLoadInProgress', build: () { when( () => graphQLClient.watchQuery(any()), ).thenReturn(rewardsObservableQuery); return SomeCubit(graphQLClient); }, act: (cubit) => cubit.doSomething(), expect: () => const [1], ); }
late final ObservableQuery _rewardsMembershipQuery;
to this:
late final _rewardsMembershipQuery;
Additional context
With in mocktail 0.2.0 works perfect. This is happen with the ObservableQuery data type of GraphQLClient.
ObservableQuery
GraphQLClient
Describe the bug
If a data type is specified to a variable that receives the mocked response, an exception is thrown with the following message:
type 'Null' is not a subtype of type .....
Example:
This works:
This does not work:
To Reproduce Steps to reproduce the behavior:
test/mocktail_test.dart
to this:
Additional context
With in mocktail 0.2.0 works perfect. This is happen with the
ObservableQuery
data type ofGraphQLClient
.