error_widget_builder_test.dart 1.51 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/widgets.dart';
6
import 'package:flutter_test/flutter_test.dart';
7
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
8 9

void main() {
10
  testWidgetsWithLeakTracking('ErrorWidget.builder', (WidgetTester tester) async {
11
    final ErrorWidgetBuilder oldBuilder = ErrorWidget.builder;
12 13 14 15
    ErrorWidget.builder = (FlutterErrorDetails details) {
      return const Text('oopsie!', textDirection: TextDirection.ltr);
    };
    await tester.pumpWidget(
16 17
      SizedBox(
        child: Builder(
18 19 20 21 22 23 24 25
          builder: (BuildContext context) {
            throw 'test';
          },
        ),
      ),
    );
    expect(tester.takeException().toString(), 'test');
    expect(find.text('oopsie!'), findsOneWidget);
26
    ErrorWidget.builder = oldBuilder;
27
  });
28

29
  testWidgetsWithLeakTracking('ErrorWidget.builder', (WidgetTester tester) async {
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    final ErrorWidgetBuilder oldBuilder = ErrorWidget.builder;
    ErrorWidget.builder = (FlutterErrorDetails details) {
      return ErrorWidget('');
    };
    await tester.pumpWidget(
      SizedBox(
        child: Builder(
          builder: (BuildContext context) {
            throw 'test';
          },
        ),
      ),
    );
    expect(tester.takeException().toString(), 'test');
    expect(find.byType(ErrorWidget), isNot(paints..paragraph()));
    ErrorWidget.builder = oldBuilder;
  });
47
}