fluttercommunity / flutter_webview_plugin

Community WebView Plugin - Allows Flutter to communicate with a native WebView.

Home Page:https://pub.dev/packages/flutter_webview_plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Testing evalJavascript failure

Z6P0 opened this issue · comments

commented

I try to run a simple test with the FlutterWebviewPlugin but I can't get it to work.

void main() {
  testWidgets('Test', (WidgetTester tester) async {
    var plugin = FlutterWebviewPlugin();
    await tester.pumpWidget(MaterialApp(
      home: Scaffold(
        body: Center(
          child: FutureBuilder<String?>(
            // future: Future.value('2'),
            future: plugin.launch('', hidden: false).then((_) => plugin.evalJavascript('1+1')),
            builder: (context, snapshot) {
              if (snapshot.hasError) throw snapshot.error!;
              if (!snapshot.hasData) return Text('...');
              return Text(snapshot.data!);
            },
          ),
        ),
      ),
    ));
    // expect(find.text('...'), findsOneWidget);
    expect(find.text('2'), findsOneWidget); // TestFailure
  });
}