@usefy/use-unmount 0.0.20 → 0.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +102 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -99,16 +99,16 @@ function WebSocketComponent() {
|
|
|
99
99
|
|
|
100
100
|
#### Parameters
|
|
101
101
|
|
|
102
|
-
| Name
|
|
103
|
-
|
|
104
|
-
| `callback` | `() => void`
|
|
105
|
-
| `options`
|
|
102
|
+
| Name | Type | Description |
|
|
103
|
+
| ---------- | ------------------- | ------------------------------------------- |
|
|
104
|
+
| `callback` | `() => void` | Function to execute when component unmounts |
|
|
105
|
+
| `options` | `UseUnmountOptions` | Optional configuration |
|
|
106
106
|
|
|
107
107
|
#### Options
|
|
108
108
|
|
|
109
|
-
| Name
|
|
110
|
-
|
|
111
|
-
| `enabled` | `boolean` | `true`
|
|
109
|
+
| Name | Type | Default | Description |
|
|
110
|
+
| --------- | --------- | ------- | -------------------------------------- |
|
|
111
|
+
| `enabled` | `boolean` | `true` | Whether to execute callback on unmount |
|
|
112
112
|
|
|
113
113
|
## React StrictMode
|
|
114
114
|
|
|
@@ -138,6 +138,101 @@ Consider using `useEffect` cleanup instead when:
|
|
|
138
138
|
|
|
139
139
|
The key difference is that `useUnmount` guarantees access to the latest values, while `useEffect` cleanup captures values at effect creation time.
|
|
140
140
|
|
|
141
|
+
## Testing
|
|
142
|
+
|
|
143
|
+
This package maintains comprehensive test coverage to ensure reliability and stability.
|
|
144
|
+
|
|
145
|
+
### Test Coverage
|
|
146
|
+
|
|
147
|
+
📊 <a href="https://geon0529.github.io/usefy/coverage/use-unmount/src/index.html" target="_blank" rel="noopener noreferrer"><strong>View Detailed Coverage Report</strong></a> (GitHub Pages)
|
|
148
|
+
|
|
149
|
+
### Test Categories
|
|
150
|
+
|
|
151
|
+
<details>
|
|
152
|
+
<summary><strong>Basic Functionality Tests</strong></summary>
|
|
153
|
+
|
|
154
|
+
- Callback execution on unmount
|
|
155
|
+
- No callback execution on mount
|
|
156
|
+
- No callback execution on rerender
|
|
157
|
+
|
|
158
|
+
</details>
|
|
159
|
+
|
|
160
|
+
<details>
|
|
161
|
+
<summary><strong>Closure Freshness Tests</strong></summary>
|
|
162
|
+
|
|
163
|
+
- Callback accesses latest values at unmount time
|
|
164
|
+
- Updated callback reference is used on unmount
|
|
165
|
+
- Latest state values are captured in callback
|
|
166
|
+
|
|
167
|
+
</details>
|
|
168
|
+
|
|
169
|
+
<details>
|
|
170
|
+
<summary><strong>Enabled Option Tests</strong></summary>
|
|
171
|
+
|
|
172
|
+
- Default enabled state (true)
|
|
173
|
+
- Explicit enabled: true
|
|
174
|
+
- Disabled when enabled: false
|
|
175
|
+
- Dynamic enabled state changes
|
|
176
|
+
- Multiple enabled toggles
|
|
177
|
+
|
|
178
|
+
</details>
|
|
179
|
+
|
|
180
|
+
<details>
|
|
181
|
+
<summary><strong>Error Handling Tests</strong></summary>
|
|
182
|
+
|
|
183
|
+
- Errors in callback are caught and logged
|
|
184
|
+
- Unmount process continues despite callback errors
|
|
185
|
+
- Non-Error objects thrown are handled
|
|
186
|
+
|
|
187
|
+
</details>
|
|
188
|
+
|
|
189
|
+
<details>
|
|
190
|
+
<summary><strong>Multiple Instances Tests</strong></summary>
|
|
191
|
+
|
|
192
|
+
- Independent instances work correctly
|
|
193
|
+
- Multiple hooks in same component
|
|
194
|
+
- Independent enabled states per instance
|
|
195
|
+
|
|
196
|
+
</details>
|
|
197
|
+
|
|
198
|
+
<details>
|
|
199
|
+
<summary><strong>Edge Cases Tests</strong></summary>
|
|
200
|
+
|
|
201
|
+
- Rapid mount/unmount cycles
|
|
202
|
+
- Undefined options handling
|
|
203
|
+
- Empty options object
|
|
204
|
+
- Null-ish enabled values
|
|
205
|
+
|
|
206
|
+
</details>
|
|
207
|
+
|
|
208
|
+
<details>
|
|
209
|
+
<summary><strong>Callback Reference Stability Tests</strong></summary>
|
|
210
|
+
|
|
211
|
+
- Effect doesn't re-run when callback reference changes
|
|
212
|
+
|
|
213
|
+
</details>
|
|
214
|
+
|
|
215
|
+
<details>
|
|
216
|
+
<summary><strong>Async Callback Tests</strong></summary>
|
|
217
|
+
|
|
218
|
+
- Async callbacks are executed on unmount
|
|
219
|
+
- Async error handling behavior
|
|
220
|
+
|
|
221
|
+
</details>
|
|
222
|
+
|
|
223
|
+
### Running Tests
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
# Run all tests
|
|
227
|
+
pnpm test
|
|
228
|
+
|
|
229
|
+
# Run tests in watch mode
|
|
230
|
+
pnpm test:watch
|
|
231
|
+
|
|
232
|
+
# Run tests with coverage report
|
|
233
|
+
pnpm test --coverage
|
|
234
|
+
```
|
|
235
|
+
|
|
141
236
|
## License
|
|
142
237
|
|
|
143
238
|
MIT
|