test_async_utils_guarded_test.dart 1 KB
Newer Older
1 2 3 4
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter/foundation.dart';
6 7 8
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

9 10 11 12 13 14
class TestTestBinding extends AutomatedTestWidgetsFlutterBinding {
  @override
  DebugPrintCallback get debugPrintOverride => testPrint;
  static void testPrint(String message, { int wrapWidth }) { print(message); }
}

15
Future<void> guardedHelper(WidgetTester tester) {
16
  return TestAsyncUtils.guard(() async {
17
    await tester.pumpWidget(const Text('Hello', textDirection: TextDirection.ltr));
18 19 20 21
  });
}

void main() {
22
  TestTestBinding();
23
  testWidgets('TestAsyncUtils - custom guarded sections', (WidgetTester tester) async {
24
    await tester.pumpWidget(Container());
25 26 27 28 29 30
    expect(find.byElementType(Container), isNotNull);
    guardedHelper(tester);
    expect(find.byElementType(Container), isNull);
    // this should fail
  });
}