testUISleepUntilRoute function

Future<bool> testUISleepUntilRoute(
  1. String route, {
  2. Map<String, dynamic>? parameters,
  3. bool partialParameters = false,
  4. int? timeoutMs,
  5. int? intervalMs,
  6. int? minMs,
  7. bool expected = false,
})

Calls testUISleepUntil checking if route is the current route (UINavigator.currentRoute).

Implementation

Future<bool> testUISleepUntilRoute(String route,
    {Map<String, dynamic>? parameters,
    bool partialParameters = false,
    int? timeoutMs,
    int? intervalMs,
    int? minMs,
    bool expected = false}) {
  var stackTrace = StackTrace.current;

  return testUISleepUntil(
    () {
      if (UINavigator.currentRoute == route) {
        if (parameters != null) {
          return _equalsParameters(
              parameters, UINavigator.currentRouteParameters,
              partialParameters: partialParameters);
        } else {
          return true;
        }
      } else {
        return false;
      }
    },
    readyTitle:
        'route: `$route`${parameters != null ? ' ; parameters: $parameters' : ''}',
    timeoutMs: timeoutMs ?? 2000,
    intervalMs: intervalMs ?? 100,
    minMs: minMs,
  ).thenChain((ok) {
    if (expected && !ok) {
      Error.throwWithStackTrace(
          TestFailure(
              "Expected route: `$route` ; current: `${UINavigator.currentRoute}`"),
          stackTrace);
    }
    return ok;
  });
}