test_async_utils_guarded_test.dart 1001 Bytes
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 16 17 18 19 20 21
Future<Null> guardedHelper(WidgetTester tester) {
  return TestAsyncUtils.guard(() async {
    await tester.pumpWidget(new Text('Hello'));
  });
}

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