addError method on stream is making the test fails

Viewed 10

I'm trying to test a screen that uses a StreamBuilder. I want to make sure that when has some error, the ErrorScreen is presented. But seems that the error is not been capture.

   @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Builder(
            builder: (context) => StreamBuilder<String>(
              stream: widget.emailStreamController.stream,
              builder: (contextStreamBuilder, snapshot) {
                if (snapshot.hasError) {
                  return ErrorScreen();
                }

                final email = snapshot.data;
                if (email != null) {
                  emailValue = email;
                  return Screen(context);
                }
                return const LoadingScreen();
              },
            ),
          ),
        );
      }
testWidgets('when stream emits error should present error screen', (tester) async {
    final stream = BehaviorSubject<String>();

    await pumpWidget(MyScreen(stream: stream));

    await tester.pump();
    stream.addError('asd');

    expectLater(find.byType(ErrorScreen), findsOneWidget);
  });
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following message was thrown running a test:
asd

When the exception was thrown, this was the stack:
#2      Subject._addError (package:rxdart/src/subjects/subject.dart:87:17)
#3      Subject.addError (package:rxdart/src/subjects/subject.dart:81:5)
0 Answers
Related