Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot await stream after upgrading to rxdart 0.27.1 to 0.27.2 in Flutter tests #691

Open
voidsp opened this issue Jul 31, 2022 · 3 comments
Assignees

Comments

@voidsp
Copy link

voidsp commented Jul 31, 2022

Hello! After I have upgraded from rxdart 0.27.1 to 0.27.5, my tests have started failing. I found the test starts failing from rxdart 0.27.2:

import 'package:flutter_test/flutter_test.dart';
import 'package:rxdart/subjects.dart';

void main() {
  group('subject test', () {
    testWidgets('wait first', (WidgetTester tester) async {
      final subject = BehaviorSubject<String>();
      subject.add('my-value');

      final Stream<String> stream = subject.stream;

      expect(await stream.first, 'my-value');

      subject.close();
    });
  });
}

This test only fails when using flutter_test instead of test (however, in the actual test case I need to use flutter_test as there are some widgets being tested), so the interesting thing is this test will work:

import 'package:flutter_test/flutter_test.dart';
import 'package:rxdart/subjects.dart';

void main() {
  group('subject test', () {
    test('wait first', () async {
      final subject = BehaviorSubject<String>();
      subject.add('my-value');

      final Stream<String> stream = subject.stream;

      expect(await stream.first, 'my-value');

      subject.close();
    });
  });
}

The first code snippet test (with flutter_test) now just hangs, but previously it ran correctly in rxdart 0.27.1. The second code snippet (with test) works on all version of rxdart.

@hoc081098 hoc081098 self-assigned this Aug 2, 2022
@hoc081098
Copy link
Collaborator

I wrap await stream.first in tester.runAsync and it works.

  group('subject test', () {
    testWidgets('wait first', (tester) async {
      final subject = BehaviorSubject<String>();
      subject.add('my-value');

      final Stream<String> stream = subject.stream;

      await tester.runAsync(() async {
        expect(await stream.first, 'my-value');
      });

      await subject.close();
    });
  });

@voidsp
Copy link
Author

voidsp commented Aug 2, 2022

Thank you @hoc081098, is this a regression in rxdart? I'm not sure why wrapping it in tester.runAsync is now required.

@CaleyD
Copy link

CaleyD commented Jul 11, 2023

I'm still running into this - unfortunately wrapping our entire widget test in runAsync causes it to fail for other reasons so its not a reasonable workaround for us.

I've found that this for some reason fixes the tests await stream.doOnData((_) {}).first but seems like an ugly hack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants