forked from firka/flutter
promote WidgetTester pumpAndSettle (#62640)
This commit is contained in:
@@ -29,6 +29,39 @@ class _CountButtonState extends State<CountButton> {
|
||||
}
|
||||
}
|
||||
|
||||
class AnimateSample extends StatefulWidget {
|
||||
@override
|
||||
_AnimateSampleState createState() => _AnimateSampleState();
|
||||
}
|
||||
|
||||
class _AnimateSampleState extends State<AnimateSample>
|
||||
with SingleTickerProviderStateMixin {
|
||||
AnimationController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(seconds: 1),
|
||||
)..forward();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
animation: _controller,
|
||||
builder: (BuildContext context, _) => Text('Value: ${_controller.value}'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('Test pump on LiveWidgetController', () async {
|
||||
runApp(MaterialApp(home: Center(child: CountButton())));
|
||||
@@ -44,6 +77,16 @@ void main() {
|
||||
expect(find.text('Counter 1'), findsOneWidget);
|
||||
});
|
||||
|
||||
test('Test pumpAndSettle on LiveWidgetController', () async {
|
||||
runApp(MaterialApp(home: Center(child: AnimateSample())));
|
||||
await SchedulerBinding.instance.endOfFrame;
|
||||
final WidgetController controller =
|
||||
LiveWidgetController(WidgetsBinding.instance);
|
||||
expect(find.text('Value: 1.0'), findsNothing);
|
||||
await controller.pumpAndSettle();
|
||||
expect(find.text('Value: 1.0'), findsOneWidget);
|
||||
});
|
||||
|
||||
test('Input event array on LiveWidgetController', () async {
|
||||
final List<String> logs = <String>[];
|
||||
runApp(
|
||||
|
||||
@@ -465,21 +465,11 @@ void main() {
|
||||
|
||||
testWidgets('pumpAndSettle control test', (WidgetTester tester) async {
|
||||
final AnimationController controller = AnimationController(
|
||||
duration: const Duration(minutes: 525600),
|
||||
duration: const Duration(seconds: 1),
|
||||
vsync: const TestVSync(),
|
||||
);
|
||||
expect(await tester.pumpAndSettle(), 1);
|
||||
controller.forward();
|
||||
try {
|
||||
await tester.pumpAndSettle();
|
||||
expect(true, isFalse);
|
||||
} catch (e) {
|
||||
expect(e, isFlutterError);
|
||||
}
|
||||
controller.stop();
|
||||
expect(await tester.pumpAndSettle(), 1);
|
||||
controller.duration = const Duration(seconds: 1);
|
||||
controller.forward();
|
||||
expect(await tester.pumpAndSettle(const Duration(milliseconds: 300)), 5); // 0, 300, 600, 900, 1200ms
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user