init_state_test.dart 1.02 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1 2 3 4
// Copyright 2015 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.

Adam Barth's avatar
Adam Barth committed
5
import 'package:flutter_test/flutter_test.dart';
Ian Hickson's avatar
Ian Hickson committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
import 'package:flutter/widgets.dart';
import 'package:test/test.dart';

List<String> ancestors = <String>[];

class TestComponent extends StatefulComponent {
  TestComponentState createState() => new TestComponentState();
}

class TestComponentState extends State<TestComponent> {
  void initState() {
    super.initState();
    context.visitAncestorElements((Element element) {
      ancestors.add(element.widget.runtimeType.toString());
      return true;
    });
  }

  Widget build(BuildContext context) => new Container();
}

void main() {
  test('initState() is called when we are in the tree', () {
    testWidgets((WidgetTester tester) {
      tester.pumpWidget(new Container(child: new TestComponent()));
      expect(ancestors, equals(<String>['Container', 'RenderObjectToWidgetAdapter<RenderBox>']));
    });
  });
}