flutter_hooks_test
2.0.0, released a year ago by wasabeef.jp
Testing utilities for Flutter hooks that avoid writing wrapper widgets.
What it does
Allows developers to test custom Flutter hooks directly without having to construct a dedicated test widget. It provides utilities for updating inputs, retrieving outputs, and handling asynchronous updates.
AI-written summary of version 2.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You are writing a library with one or more custom hooks not directly tied to a widget
- You have a complex hook that is difficult to test through widget interactions
Skip it when
- Your hook is defined alongside a widget and is only used there
- Your hook is easy to test by just testing the widgets using it
Strengths
- Simplifies custom hook testing without requiring manual widget boilerplate
- Provides async waiting utilities like waitFor and waitForNextUpdate
- Supports wrappers to supply providers to hooks
Weaknesses
- Not necessary if your hooks are simple and tested purely via widget tests
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 2
Add flutter_hooks_test to your dev_dependencies.
testWidgets('should rebuild widget each time returned function is called', (tester) async {
var buildCount = 0;
final result = await buildHook(
() {
buildCount++;
return useUpdate();
},
wrapper: (child) => Container(child: child),
);
expect(buildCount, 1);
final update = result.current;
await act(() => update());
expect(buildCount, 2);
});Alternatives
Packages that do the same job and could replace flutter_hooks_test.
Works with
Packages commonly used together with flutter_hooks_test: ones it builds on, ones built on it, and its own family.