Skip to content

Commit

Permalink
#6 - Fix for tests running as both widget and integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomalabaster committed Dec 28, 2023
1 parent 0e93f90 commit 6aa3330
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions example/test/main_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:flutter_app_lock_example/main.dart' as app;
import 'package:integration_test/integration_test.dart';

final myHomePage = find.byKey(const Key('MyHomePage'));
final lockScreen = find.byKey(const Key('LockScreen'));
Expand Down Expand Up @@ -41,7 +42,11 @@ Future<void> enterBackgroundForDuration(
WidgetTester tester, Duration duration) async {
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.hidden);

await Future.delayed(duration);
if (tester.binding is IntegrationTestWidgetsFlutterBinding) {
await Future.delayed(duration);
} else {
await tester.pumpAndSettle(duration);
}

tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);

Expand Down Expand Up @@ -188,10 +193,10 @@ void main() {
testWidgets('The lock screen is not visible',
(WidgetTester tester) async {
app.main(
enabled: false, backgroundLockLatency: const Duration(seconds: 1));
enabled: false, backgroundLockLatency: const Duration(seconds: 2));

await enableAfterLaunch(tester);
await enterBackgroundForDuration(tester, const Duration(seconds: 0));
await enterBackgroundForDuration(tester, const Duration(seconds: 1));

expect(lockScreen, findsNothing);
});
Expand Down

0 comments on commit 6aa3330

Please sign in to comment.