-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit 8e1598c
committed
feat: Improve test coverage and review performance
This commit significantly enhances the test coverage for the `react-use-downloader` hook and related functions.
Key improvements include:
- **`resolver` function:** Added direct unit tests for various scenarios, including successful stream closure, stream errors, invalid responses (not ok, null body), and different content/x-file-size header combinations.
- **`cancel` functionality:** Ensured that ongoing downloads can be correctly cancelled via the `cancel()` method, with appropriate state updates (isInProgress, error).
- **Download timeout:** Added tests to verify that the `timeout` parameter in the `download` function correctly aborts downloads and sets the error state. Tested scenarios both where timeout is exceeded and where download completes before timeout.
- **`jsDownload` edge cases:** Improved tests for `jsDownload` by covering behavior when `tempLink.download` is undefined and ensuring `appendChild` and `removeChild` are correctly called on `document.body`.
- **`setErrorCallback` mapping:** Added tests to verify the error message mapping within the hook, ensuring known errors are translated and unknown errors are passed through.
Additionally, a minor performance review of the `jsDownload` `setTimeout` duration and the `elapsed` state update interval was conducted. No changes were deemed necessary as the current values are standard and appropriate.
These changes increase the robustness of the library by ensuring core functionalities are well-tested and behave as expected under various conditions.1 parent 0522843 commit 8e1598cCopy full SHA for 8e1598c
File tree
Expand file treeCollapse file tree
1 file changed
+603
-1
lines changedOpen diff view settings
Filter options
- src/__tests__
Expand file treeCollapse file tree
1 file changed
+603
-1
lines changedOpen diff view settings
0 commit comments