So i'm doing some test here is my test script
Widget MyWidget() {
return MaterialApp(
home: BlocProvider(
create: (context) {
return SplashScreenBloc(url: "google.com");
},
child: SplashScreen(),
),
);
}
testWidgets('should render LoadingIndicator when state is Loading State',
(WidgetTester tester) async {
final expectedStates = [Default(), LoadingState()];
whenListen<SplashScreenState>(splashScreenBloc,
Stream<SplashScreenState>.fromIterable(expectedStates));
await tester.pumpWidget(MyWidget());
expect(find.byKey(Key("splash_loading_bar")), findsOneWidget);
});
I get this message
The test description was: should render LoadingIndicator when state is Loading State
my splash_screen
BlocBuilder<SplashScreenBloc, SplashScreenState>(
builder: (context, state) {
if (state is Default || state is LoadingState) {
return CircularProgressIndicator(
key: Key("splash_loading_bar"),
);
} else if (state is NotConnected) {
return Text("Could not connect to server", key: Key("splash_screen_not_connected"));
} else if (state is Connected) {
return Text(
"Connected",
key: Key("splash_screen_connected"),
);
} else {
return Container();
}
},
)
Hi @bobykurniawan11 馃憢
Thanks for opening an issue!
Can you please provide a link to a sample app which reproduces the issue? I鈥檓 guessing the issue is you鈥檙e using whenListen to text the BlocBuilder when all you need to do is use when instead
when(splashScreenBloc.state).thenReturn(LoadingState());
whenListen is only needed if you鈥檙e testing BlocListener code (because BlocListener requires a state change to occur in order to be triggered) whereas BlocBuilder always needs to render a widget so you can just use the regular when API from mockito.
Hope that helps 馃憤
hi @felangel , thanks for answering.
Here is my script https://github.com/bobykurniawan11/hello_chat
i already try
when(splashScreenBloc.state).thenReturn(LoadingState());
but the result still same
going to close this. I'm separating the widget test and bloc test
Most helpful comment
going to close this. I'm separating the widget test and bloc test