TestWidgetsFlutterBinding should dispose old RestorationManager on reset. (#133999)

This commit is contained in:
Polina Cherkasova 2023-09-07 17:49:33 -07:00 committed by GitHub
parent e08173e767
commit 0d30546c74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -244,6 +244,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
/// If [registerTestTextInput] returns true when this method is called,
/// the [testTextInput] is configured to simulate the keyboard.
void reset() {
_restorationManager?.dispose();
_restorationManager = null;
resetGestureBinding();
testTextInput.reset();

View File

@ -0,0 +1,20 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_test/flutter_test.dart';
void main() {
test('Disposes restoration manager on reset.', () {
final AutomatedTestWidgetsFlutterBinding binding = AutomatedTestWidgetsFlutterBinding();
int oldCounter = 0;
final TestRestorationManager oldRestorationManager = binding.restorationManager;
oldRestorationManager.addListener(() => oldCounter++);
oldRestorationManager.notifyListeners();
expect(oldCounter, 1);
binding.reset();
expect(oldRestorationManager.notifyListeners, throwsA((Object e) => e.toString().contains('disposed')));
});
}