I cannot seem to get my widget test to work, and while the documentation does not specifically cover testing with state management, this issue (https://github.com/felangel/mocktail/issues/42) pretty much confirms that what I discerned seems to be correct, however, I keep running into the error
type 'Null' is not a subtype of type 'Stream<BulkUploadState>'.
class MockBulkUploadCubit extends Mock implements BulkUploadCubit {}
class FakeBulkUploadState extends Fake implements BulkUploadState {}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
late MockBulkUploadCubit mockCubit;
setUpAll(() {
registerFallbackValue<BulkUploadState>(FakeBulkUploadState());
});
setUp(() {
mockCubit = MockBulkUploadCubit();
});
testWidgets(
"BulkSearchInput",
(tester) async {
when(() => mockCubit.state).thenReturn(BulkUploadState.initial());
await tester.pumpWidget(
BlocProvider<BulkUploadCubit>.value(
value: mockCubit,
child: const MaterialApp(home: BulkSearchInput()),
),
);
await tester.pumpAndSettle();
expect(find.byType(TextFormField), findsOneWidget);
},
);
}
Currently pulling the state off context.select however when refactoring the widget to use BlocSelector I get the same error.
Not sure what I am missing here.