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

import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
7
import 'package:flutter_test/flutter_test.dart';
8
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
9 10 11

/// Unit tests error.dart's usage via ErrorWidget.
void main() {
12
  const String errorMessage = 'Some error message';
13

14
  testWidgetsWithLeakTracking('test draw error paragraph', (WidgetTester tester) async {
15
    await tester.pumpWidget(ErrorWidget(Exception(errorMessage)));
16 17 18
    expect(
      find.byType(ErrorWidget),
      paints
19
        ..rect(rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 600.0))
20 21
        ..paragraph(offset: const Offset(64.0, 96.0)),
    );
22

23
    final Widget error = Builder(builder: (BuildContext context) => throw 'pillow');
24

25
    await tester.pumpWidget(Center(child: SizedBox(width: 100.0, child: error)));
26
    expect(tester.takeException(), 'pillow');
27 28 29
    expect(
      find.byType(ErrorWidget),
      paints
30
        ..rect(rect: const Rect.fromLTWH(0.0, 0.0, 100.0, 600.0))
31 32
        ..paragraph(offset: const Offset(0.0, 96.0)),
    );
33

34
    await tester.pumpWidget(Center(child: SizedBox(height: 100.0, child: error)));
35
    expect(tester.takeException(), null);
36

37
    await tester.pumpWidget(Center(child: SizedBox(key: UniqueKey(), height: 100.0, child: error)));
38
    expect(tester.takeException(), 'pillow');
39 40 41
    expect(
      find.byType(ErrorWidget),
      paints
42
        ..rect(rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 100.0))
43 44
        ..paragraph(offset: const Offset(64.0, 0.0)),
    );
45 46

    RenderErrorBox.minimumWidth = 800.0;
47
    await tester.pumpWidget(Center(child: error));
48
    expect(tester.takeException(), 'pillow');
49 50 51
    expect(
      find.byType(ErrorWidget),
      paints
Dan Field's avatar
Dan Field committed
52
        ..rect(rect: const Rect.fromLTWH(0.0, 0.0, 800.0, 600.0))
53 54
        ..paragraph(offset: const Offset(0.0, 96.0)),
    );
55

56
    await tester.pumpWidget(Center(child: error));
57
    expect(tester.takeException(), null);
58 59 60
    expect(
      find.byType(ErrorWidget),
      paints
61
        ..rect(color: const Color(0xF0900000))
62 63
        ..paragraph(),
    );
64 65

    RenderErrorBox.backgroundColor = const Color(0xFF112233);
66
    await tester.pumpWidget(Center(child: error));
67
    expect(tester.takeException(), null);
68 69 70
    expect(
      find.byType(ErrorWidget),
      paints
71
        ..rect(color: const Color(0xFF112233))
72 73
        ..paragraph(),
    );
74 75
  });
}