verifyAllScopesClosed static method

void verifyAllScopesClosed()

Verifies that there are no guarded methods currently pending (see guard).

This is used at the end of tests to ensure that nothing leaks out of the test.


static void verifyAllScopesClosed() {
  if (_scopeStack.isNotEmpty) {
    final List<DiagnosticsNode> information = <DiagnosticsNode>[
      ErrorSummary('Asynchronous call to guarded function leaked.'),
      ErrorHint('You must use "await" with all Future-returning test APIs.'),
    for (final _AsyncScope scope in _scopeStack) {
      final _StackEntry? guarder = _findResponsibleMethod(scope.creationStack, 'guard', information);
      if (guarder != null) {
          'The guarded method "${guarder.methodName}" '
          '${guarder.className != null ? "from class ${guarder.className} " : ""}'
          'was called from ${guarder.callerFile} '
          'on line ${guarder.callerLine}, '
          'but never completed before its parent scope closed.'
    throw FlutterError.fromParts(information);