expectRxChange<T> static method

Future<void> expectRxChange<T>(
  1. Rx<T> rx,
  2. T expectedValue, {
  3. Duration timeout = const Duration(seconds: 1),
})

Test that a reactive value changes to expected value

Implementation

static Future<void> expectRxChange<T>(
  Rx<T> rx,
  T expectedValue, {
  Duration timeout = const Duration(seconds: 1),
}) async {
  final completer = Completer<void>();

  void listener() {
    if (rx.value == expectedValue) {
      completer.complete();
      rx.removeListener(listener);
    }
  }

  rx.addListener(listener);

  try {
    await completer.future.timeout(timeout);
  } catch (e) {
    rx.removeListener(listener);
    throw Exception(
        'Expected Rx value to change to $expectedValue but timeout occurred');
  }
}