run_app_async_test.dart 955 Bytes
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/material.dart';
import 'package:flutter_test/flutter_test.dart';
7
import 'package:fake_async/fake_async.dart';
8 9 10 11

void main() {
  setUp(() {
    WidgetsFlutterBinding.ensureInitialized();
12
    WidgetsBinding.instance!.resetEpoch();
13 14 15 16 17 18 19 20 21 22 23 24 25
  });

  test('WidgetBinding build rendering tree and warm up frame back to back', () {
    final FakeAsync fakeAsync = FakeAsync();
    fakeAsync.run((FakeAsync async) {
      runApp(
        const MaterialApp(
          home: Material(
            child: Text('test'),
          ),
        ),
      );
      // Rendering tree is not built synchronously.
26
      expect(WidgetsBinding.instance!.renderViewElement, isNull);
27
      fakeAsync.flushTimers();
28
      expect(WidgetsBinding.instance!.renderViewElement, isNotNull);
29 30 31
    });
  });
}