Skip to content
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

fix!: Updates for Flutter 3.16.0/Dart 3.2 #65

Merged
merged 6 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class MySettingsPage extends StatelessWidget {
void main() {
testWidgets('pushes SettingsPage when TextButton is tapped', (tester) async {
final navigator = MockNavigator();
when(navigator.canPop).thenReturn(true);
when(() => navigator.push<void>(any())).thenAnswer((_) async {});

await tester.pumpWidget(
Expand Down
1 change: 1 addition & 0 deletions example/test/ui/home_screen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ void main() {

setUp(() {
navigator = MockNavigator();
when(() => navigator.canPop()).thenReturn(true);
when(() => navigator.push<String?>(any())).thenAnswer((_) async => null);
when(
() => navigator.push<QuizOption>(any()),
Expand Down
1 change: 1 addition & 0 deletions example/test/ui/pincode_screen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void main() {

setUp(() {
navigator = MockNavigator();
when(() => navigator.canPop()).thenReturn(true);
});

testWidgets('.route renders PincodeScreen', (tester) async {
Expand Down
1 change: 1 addition & 0 deletions example/test/ui/quiz_dialog_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void main() {

setUp(() {
navigator = MockNavigator();
when(() => navigator.canPop()).thenReturn(true);
});

testWidgets('.show opens dialog', (tester) async {
Expand Down
13 changes: 12 additions & 1 deletion lib/src/mock_navigator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class _MockMaterialPageRoute extends MaterialPageRoute<void> {

void hackOverlays() {
for (var i = 0; i < overlayEntries.length; i++) {
final state = OverlayState();
// Entry can only be inserted when the state is mounted
final state = _MockOverlayState().._mounted = true;
final entry = OverlayEntry(builder: (_) => const SizedBox());
try {
// We need to call insert since that is the only way to populate the
Expand All @@ -17,11 +18,21 @@ class _MockMaterialPageRoute extends MaterialPageRoute<void> {
// so we just ignore the error and the hack will do its job.
state.insert(entry);
} catch (_) {}
// Set mounted back to false to make sure the state doesn't get
// marked as dirty during OverlayEntry.remove().
state._mounted = false;
overlayEntries[i] = entry;
}
}
}

class _MockOverlayState extends OverlayState {
late bool _mounted;

@override
bool get mounted => _mounted;
}

class _FakeRoute<T> extends Fake implements Route<T> {}

/// {@template mock_navigator_provider}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ homepage: https://github.com/VeryGoodOpenSource/mockingjay

environment:
sdk: ">=2.18.0 <4.0.0"
flutter: ">=3.7.3"
flutter: ">=3.16.0"

dependencies:
flutter:
Expand Down
1 change: 1 addition & 0 deletions test/src/example_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class MySettingsPage extends StatelessWidget {
void main() {
testWidgets('pushes SettingsPage when TextButton is tapped', (tester) async {
final navigator = MockNavigator();
when(navigator.canPop).thenReturn(true);
when(() => navigator.push<void>(any())).thenAnswer((_) async {});

await tester.pumpWidget(
Expand Down
3 changes: 3 additions & 0 deletions test/src/mock_navigator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void main() {

setUp(() {
navigator = MockNavigator();
when(() => navigator.canPop()).thenReturn(true);
});

test('toString returns normally', () {
Expand Down Expand Up @@ -198,6 +199,8 @@ void main() {
),
);

// Called by NavigatorState.didChangeDependencies initially
verify(() => navigator.canPop()).called(1);
await tester.tap(find.byType(TextButton));
verify(() => navigator.canPop()).called(1);
});
Expand Down