Skip to content

Commit 26e52af

Browse files
committed
docs: update documentation for v2.0.0 release
1 parent 2b64440 commit 26e52af

File tree

4 files changed

+95
-32
lines changed

4 files changed

+95
-32
lines changed

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
## 2.0.0
2+
3+
**BREAKING CHANGES**
4+
5+
- Remove `debug()` methods from `HookResult` and `_HookTestingAction` classes
6+
- Internal implementation restructured with new base classes
7+
8+
**Features**
9+
10+
- Add type-safe API with separate `buildHook()` and `buildHookWithProps()` functions
11+
- Implement build history tracking with `result.all` and `result.buildCount` properties
12+
- Add `waitFor` utilities for async testing scenarios
13+
- `waitFor(condition)` - Wait for condition to become true
14+
- `waitForValueToChange(getValue)` - Wait for value to change
15+
- `result.waitForNextUpdate()` - Wait for hook rebuild
16+
- `result.waitForValueToMatch(predicate)` - Wait for specific condition
17+
18+
**Improvements**
19+
20+
- Improve DartDoc accuracy and clarity
21+
- Update documentation with Flutter terminology (widget vs component)
22+
- Better error messages and examples in documentation
23+
124
## 1.0.0
225

326
**Feature**

CLAUDE.md

Lines changed: 69 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -52,43 +52,76 @@ bun run prepare
5252

5353
## Architecture and Code Structure
5454

55-
### Core API
55+
### Core API (v2.0.0)
5656

5757
The library exports a single file `lib/flutter_hooks_test.dart` containing:
5858

59-
1. **`buildHook<T, P>`** - Main function to test hooks
59+
1. **`buildHook<T>()`** - Test hooks without props
6060
- Generic `T`: Return type of the hook
61-
- Generic `P`: Props type for parameterized hooks
62-
- Returns `_HookTestingAction<T>` with methods:
61+
- Returns `HookResult<T>` with methods:
6362
- `current`: Access current hook value
64-
- `rebuild([props])`: Trigger rebuild with optional new props
63+
- `rebuild()`: Trigger rebuild and update history
6564
- `unmount()`: Unmount the hook
65+
- `all`: Build history for debugging
66+
- `buildCount`: Number of builds
6667

67-
2. **`act`** - Wraps state changes to ensure proper Flutter test lifecycle
68+
2. **`buildHookWithProps<T, P>()`** - Test hooks with props
69+
- Generic `T`: Return type, `P`: Props type
70+
- Returns `HookResultWithProps<T, P>` with additional:
71+
- `rebuildWithProps(P props)`: Rebuild with new props
72+
73+
3. **`act`** - Wraps state changes to ensure proper Flutter test lifecycle
74+
75+
4. **`waitFor` utilities** - Async testing helpers
76+
- `waitFor(condition)`: Wait for condition to be true
77+
- `waitForValueToChange(getValue)`: Wait for value change
78+
- `result.waitForNextUpdate()`: Wait for hook rebuild
79+
- `result.waitForValueToMatch(predicate)`: Wait for specific condition
6880
- Similar to React's `act` function
6981
- Required when changing hook state
7082

71-
### Testing Pattern
83+
### Testing Patterns (v2.0.0)
7284

7385
```dart
74-
// Basic hook test structure
75-
final result = await buildHook((_) => useMyHook());
86+
// Basic hook test (no props)
87+
final result = await buildHook(() => useMyHook());
7688
await act(() => result.current.doSomething());
7789
expect(result.current.value, expectedValue);
7890
91+
// Hook with props
92+
final result = await buildHookWithProps(
93+
(count) => useCounter(count),
94+
initialProps: 5,
95+
);
96+
await result.rebuildWithProps(10);
97+
expect(result.current.value, 10);
98+
7999
// With wrapper widget
80100
final result = await buildHook(
81-
(_) => useMyHook(),
101+
() => useMyHook(),
82102
wrapper: (child) => Provider(child: child),
83103
);
104+
105+
// Async testing with waitFor
106+
await act(() => result.current.startAsync());
107+
await waitFor(() => !result.current.isLoading);
108+
expect(result.current.data, isNotNull);
109+
110+
// History tracking
111+
expect(result.buildCount, 1);
112+
expect(result.all.length, 1);
113+
await result.rebuild();
114+
expect(result.buildCount, 2);
84115
```
85116

86-
### Internal Implementation
117+
### Internal Implementation (v2.0.0)
87118

88119
- Uses `TestWidgetsFlutterBinding` for test environment
89-
- Creates a minimal widget tree with `HookBuilder`
90-
- Manages completer-based async operations for mount/unmount
91-
- Preserves hook state across rebuilds using keys
120+
- Creates minimal widget tree with `HookBuilder`
121+
- `_BaseHookResult<T>` base class eliminates code duplication
122+
- Build history tracking with automatic value capture
123+
- Separate result classes for hooks with/without props
124+
- Helper functions (`_applyWrapper`) and constants (`_kEmptyWidget`)
92125

93126
## Testing Approach
94127

@@ -104,40 +137,46 @@ final result = await buildHook(
104137
- Pre-commit hooks format code automatically
105138
- CI runs on Ubuntu with asdf version management
106139

107-
## Important Conventions
140+
## Important Conventions (v2.0.0)
108141

109-
1. **Type Safety**: Always specify generic types when using `buildHook`
110-
2. **Act Wrapper**: Always wrap state changes in `act()`
111-
3. **Async Handling**: Most operations return Futures - use `await`
112-
4. **Testing**: Test both happy paths and edge cases (mount/unmount/rebuild)
142+
1. **API Selection**: Use `buildHook()` for hooks without props, `buildHookWithProps()` for hooks with props
143+
2. **Type Safety**: Generic types are automatically inferred in most cases
144+
3. **Act Wrapper**: Always wrap state changes in `act()`
145+
4. **Async Testing**: Use `waitFor` utilities for async operations
146+
5. **History Tracking**: Use `result.all` and `result.buildCount` for debugging
147+
6. **Rebuilds**: Call `rebuild()` after state changes to update history
148+
7. **Testing**: Test mount/unmount/rebuild scenarios and async state changes
113149

114150
## Version Requirements
115151

116152
- Dart SDK: `>=2.17.0 <4.0.0`
117153
- Flutter: `>=3.20.0`
118154
- Uses Flutter hooks `^0.21.2`
119155

120-
## Release Process
156+
## Release Process (v2.0.0+)
121157

122-
Releases are fully automated via GitHub Actions:
158+
Releases are fully automated via GitHub Actions with OIDC authentication:
123159

124160
### Creating a Release
125161

126162
1. **Update version**: Update version in `pubspec.yaml`
127-
2. **Update changelog**: Run `git cliff --unreleased --tag v1.0.1 --output CHANGELOG.md`
128-
3. **Commit changes**: `git commit -am "chore(release): prepare for v1.0.1"`
129-
4. **Create tag**: `git tag v1.0.1`
130-
5. **Push**: `git push origin main --tags`
163+
2. **Commit changes**: `git commit -am "chore: bump version to v2.0.1"`
164+
3. **Create tag**: `git tag v2.0.1`
165+
4. **Push**: `git push origin main --tags`
166+
167+
Changelog is automatically generated from conventional commits.
131168

132169
### Automated Release Steps
133170

134171
When a tag matching `v[0-9]+.[0-9]+.[0-9]+*` is pushed:
135172

136-
1. **CI Validation**: All tests, formatting, and analysis must pass
137-
2. **Dry Run**: Package publication is tested
138-
3. **Release Notes**: Auto-generated using git-cliff from conventional commits
139-
4. **GitHub Release**: Created with generated release notes
140-
5. **pub.dev Publication**: Package is published automatically
173+
1. **Environment Setup**: Flutter, Dart, Bun, and Melos
174+
2. **Dependencies**: Install and bootstrap packages with Melos and Bun
175+
3. **CI Validation**: All tests, formatting, and analysis must pass
176+
4. **Dry Run**: Package publication tested with OIDC authentication
177+
5. **Release Notes**: Auto-generated using git-cliff from conventional commits
178+
6. **GitHub Release**: Created with generated release notes
179+
7. **pub.dev Publication**: Published automatically with OIDC (no token required)
141180

142181
### Commit Convention
143182

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ the results.
6161

6262
```yaml
6363
dev_dependencies:
64-
flutter_hooks_test: ^1.0.0
64+
flutter_hooks_test: ^2.0.0
6565
```
6666
6767
## Example
@@ -133,3 +133,4 @@ Plugin issues that are not specific to [Flutter Hooks Testing Library](https://g
133133
If you wish to contribute a change to this project,
134134
please review our [contribution guide](https://github.com/wasabeef/flutter_hooks_test/blob/main/CONTRIBUTING.md)
135135
and open a [pull request](https://github.com/wasabeef/flutter_hooks_test/pulls).
136+

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: flutter_hooks_test
22

33
description: Simple and complete Flutter hooks testing utilities that encourage good testing practices.
4-
version: 1.0.0
4+
version: 2.0.0
55
homepage: https://github.com/wasabeef/flutter_hooks_test
66
repository: https://github.com/wasabeef/flutter_hooks_test
77
documentation: https://github.com/wasabeef/flutter_hooks_test

0 commit comments

Comments
 (0)