-
-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Widget testing #41
Comments
I needed to adjust my widget tests after adding the
Now for integration testing, running the app on an emulator or an actual device, everything works as normal, but for widget testing that was not the case. In order to fix this, I've done the following in my widget test: // imports for creating mock versions...
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:network_info_plus/network_info_plus.dart';
import 'package:firebase_auth_mocks/firebase_auth_mocks.dart';
// ...
testWidgets('Smoke test', (WidgetTester tester) async {
// Wrap in `runAsync` in order to do `await Future.delayed`, otherwise infinite loop
await tester.runAsync(() async {
final auth = MockFirebaseAuth();
final connectivityService = TestConnectivityService(ConnectivityResult.wifi);
final testNetworkInfoService = TestNetworkInfoService();
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp(
firebaseAuth: auth,
networkInfo: testNetworkInfoService,
connectivity: connectivityService,
));
// Just a millisecond of delay is enough to give the OfflineBuilder's StreamBuilder
// time to load the initial result (wifi), no need to match the (default) debounce duration or anything
await Future.delayed(const Duration(milliseconds: 1));
// Pump and settle so the OfflineBuilder can render its child, instead of the empty SizedBox
await tester.pumpAndSettle();
// Your first screen should be fully loaded now
// ...
});
}); Please note that I copied over the Now the issue I'm currently still having, is the warning for the @override
Widget build(BuildContext context) {
// WARNING: The member 'OfflineBuilder.initialize' can only be used within 'package:flutter_offline/src/main.dart' or a test.
return OfflineBuilder.initialize(
connectivityBuilder: _buildMyAppStateData,
connectivityService: widget.connectivity,
wifiInfo: widget.networkInfo,
// A dummy child that should never be rendered... (right?)
child: const Text('Loading...'),
);
}
/// Build the child Widget of the [OfflineBuilder], based on the given connectivity state
Widget _buildMyAppStateData(BuildContext context, ConnectivityResult connectivity, Widget defaultChild) {
// ...
} So I have a working widget test, but there are 2 main issues I'd still like to solve:
I'm currently still looking for ways to fix this, but in the meanwhile feedback or hints are more than welcome! |
Hello, do you have a working example of a widget test for this? Because to me it looks like everything in the
child
ofOfflineBuilder
doesn't get picked up by widget tests and isn't found with finders. :(The text was updated successfully, but these errors were encountered: