mockingjay
一個讓 Flutter 中的導航模擬、測試和驗證變得輕鬆的套件。由 Very Good Ventures 🦄 創建
- 星標
- 116
- 分支
- 11
- 最近推送(UTC)
- 2026年4月14日
- 專案狀態
- 已封存
原始 README
以下為英文專案原文快照,最新內容請造訪 GitHub。
🕊 mockingjay
Developed with 💙 by Very Good Ventures 🦄
⚠️ This package is deprecated and no longer actively maintained.
The Flutter ecosystem has shifted toward Navigator 2.0 and declarative routing solutions such as
go_router. Mockingjay, which targets Navigator 1.0 APIs, no longer aligns with the direction of the ecosystem.The repository remains public and available to fork. For full migration guidance, see DEPRECATION.md.
A package that makes it easy to mock, test and verify navigation calls in Flutter. It works in tandem with mocktail, allowing you to mock a navigator the same way you would any other object, making it easier to test navigation behavior independently from the UI it's supposed to render.
Usage
To use the package in your tests, install it via dart pub add:
dart pub add dev:mockingjay
Then, in your tests, create a MockNavigator class like so:
import 'package:mockingjay/mockingjay.dart';
final navigator = MockNavigator();
Now you can create a new MockNavigator and pass it to a MockNavigatorProvider.
Any widget looking up the nearest Navigator.of(context) from that point will now receive the MockNavigator, allowing you to mock (using when) and verify any navigation calls. Use the included matchers to more easily match specific route names and types.
Note: make sure the MockNavigatorProvider is constructed below the MaterialApp. Otherwise, any Navigator.of(context) call will return a real NavigatorState instead of the mock.
Example
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockingjay/mockingjay.dart';
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: TextButton(
onPressed: () => Navigator.of(context).push(MySettingsPage.route()),
child: const Text('Navigate'),
),
);
}
}
class MySettingsPage extends StatelessWidget {
const MySettingsPage({super.key});
static Route<void> route() {
return MaterialPageRoute(
builder: (_) => const MySettingsPage(),
settings: const RouteSettings(name: '/settings'),
);
}
@override
Widget build(BuildContext context) {
return const Scaffold();
}
}
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(
MaterialApp(
home: MockNavigatorProvider(
navigator: navigator,
child: const MyHomePage(),
),
),
);
await tester.tap(find.byType(TextButton));
verify(
() => navigator.push<void>(
any(
that: isRoute<void>(
whereName: equals('/settings'),
),
),
),
).called(1);
});
}
分類
使用的依賴
依賴清單 6 項
- flutter
{"sdk":"flutter"} - flutter_test
{"sdk":"flutter"} - matcher
^0.12.17 - mocktail
^1.0.4 - test
^1.26.3 - very_good_analysis開發依賴
^10.0.0
如何選擇適合專案的儲存庫?
先依使用情境篩選,再比較專案活躍情況,最後到原始儲存庫確認使用要求。
- 透過儲存庫名稱、作者或描述搜尋,再依技術分類縮小範圍。
- 綜合星標、分支與最近推送比較專案;星標反映社群關注,不保證品質。
- 使用前在 GitHub 確認 README、授權條款與 Issues。
來源與維護
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗

