【发布时间】:2019-02-25 22:48:12
【问题描述】:
我要测试的是: 用户点击一个按钮,小吃栏会显示五秒钟。
这是带有钥匙的脚手架:
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(debugLabel: "scaffoldState");
...
builder: (context, viewModel) => Scaffold(
key: _scaffoldKey,
然后是按钮和snackBar的代码:
child: FlatButton(key: Key('loginButton'), onPressed: () {
validate();
...
validate() {
// FormState object can be used to save, reset, and validate
// every FormField that is a descendant of the associated Form.
final FormState form = _formKey.currentState;
if (form.validate()) {
form.save();
form.reset();
//implementation of the snackBar:
_scaffoldKey.currentState.showSnackBar(new SnackBar(
duration: new Duration(seconds: 5)
...
我正在尝试以这种方式测试这种行为(我也在使用 Flutter redux):
void main(){
final store = Store<AppState>(reducer, initialState: AppState.initialState());
testWidgets("MaterialApp local", (WidgetTester tester) async{
await tester.pumpWidget(new StoreProvider(
store: store,
child: MaterialApp(
home: LoginView(),
)));
await tester.pumpAndSettle();
await tester.press(find.byKey(Key("loginButton")));
expect();
我不知道要在里面放什么。我试图使用 find.ByKey(Key)) 获取 GlobalKey 并搜索 debugLabel,但它似乎不起作用。我从 2 天开始就在尝试,但我找不到出路。
【问题讨论】: