@usefy/use-unmount 0.0.20 → 0.0.21

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.
Files changed (2) hide show
  1. package/README.md +107 -7
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -99,16 +99,16 @@ function WebSocketComponent() {
99
99
 
100
100
  #### Parameters
101
101
 
102
- | Name | Type | Description |
103
- |------|------|-------------|
104
- | `callback` | `() => void` | Function to execute when component unmounts |
105
- | `options` | `UseUnmountOptions` | Optional configuration |
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 | Type | Default | Description |
110
- |------|------|---------|-------------|
111
- | `enabled` | `boolean` | `true` | Whether to execute callback on unmount |
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,106 @@ 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
+ | Category | Coverage |
148
+ | ---------- | ------------ |
149
+ | Statements | 100% (10/10) |
150
+ | Branches | 100% (4/4) |
151
+ | Functions | 100% (3/3) |
152
+ | Lines | 100% (10/10) |
153
+
154
+ ### Test Categories
155
+
156
+ <details>
157
+ <summary><strong>Basic Functionality Tests</strong></summary>
158
+
159
+ - Callback execution on unmount
160
+ - No callback execution on mount
161
+ - No callback execution on rerender
162
+
163
+ </details>
164
+
165
+ <details>
166
+ <summary><strong>Closure Freshness Tests</strong></summary>
167
+
168
+ - Callback accesses latest values at unmount time
169
+ - Updated callback reference is used on unmount
170
+ - Latest state values are captured in callback
171
+
172
+ </details>
173
+
174
+ <details>
175
+ <summary><strong>Enabled Option Tests</strong></summary>
176
+
177
+ - Default enabled state (true)
178
+ - Explicit enabled: true
179
+ - Disabled when enabled: false
180
+ - Dynamic enabled state changes
181
+ - Multiple enabled toggles
182
+
183
+ </details>
184
+
185
+ <details>
186
+ <summary><strong>Error Handling Tests</strong></summary>
187
+
188
+ - Errors in callback are caught and logged
189
+ - Unmount process continues despite callback errors
190
+ - Non-Error objects thrown are handled
191
+
192
+ </details>
193
+
194
+ <details>
195
+ <summary><strong>Multiple Instances Tests</strong></summary>
196
+
197
+ - Independent instances work correctly
198
+ - Multiple hooks in same component
199
+ - Independent enabled states per instance
200
+
201
+ </details>
202
+
203
+ <details>
204
+ <summary><strong>Edge Cases Tests</strong></summary>
205
+
206
+ - Rapid mount/unmount cycles
207
+ - Undefined options handling
208
+ - Empty options object
209
+ - Null-ish enabled values
210
+
211
+ </details>
212
+
213
+ <details>
214
+ <summary><strong>Callback Reference Stability Tests</strong></summary>
215
+
216
+ - Effect doesn't re-run when callback reference changes
217
+
218
+ </details>
219
+
220
+ <details>
221
+ <summary><strong>Async Callback Tests</strong></summary>
222
+
223
+ - Async callbacks are executed on unmount
224
+ - Async error handling behavior
225
+
226
+ </details>
227
+
228
+ ### Running Tests
229
+
230
+ ```bash
231
+ # Run all tests
232
+ pnpm test
233
+
234
+ # Run tests in watch mode
235
+ pnpm test:watch
236
+
237
+ # Run tests with coverage report
238
+ pnpm test --coverage
239
+ ```
240
+
141
241
  ## License
142
242
 
143
243
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usefy/use-unmount",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "description": "A React hook that executes a callback when the component unmounts",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",