get_state_test.dart
1.06 KB
1
2
3
4
5
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:get/get.dart';
void main() {
testWidgets("GetController smoke test", (tester) async {
await tester.pumpWidget(
MaterialApp(
home: GetBuilder<Controller>(
init: Controller(),
builder: (controller) => Column(
children: [
Text(
'${controller.counter}',
),
FlatButton(
child: Text("increment"),
onPressed: () => controller.increment(),
)
],
),
),
),
);
expect(find.text("0"), findsOneWidget);
Controller.to.increment();
await tester.pump();
expect(find.text("1"), findsOneWidget);
await tester.tap(find.text('increment'));
await tester.pump();
expect(find.text("2"), findsOneWidget);
});
}
class Controller extends GetController {
static Controller get to => Get.find();
int counter = 0;
void increment() {
counter++;
update(this);
}
}