feat: Improve test coverage and review performance #32
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit significantly enhances the test coverage for the
react-use-downloaderhook and related functions.Key improvements include:
resolverfunction: 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.cancelfunctionality: Ensured that ongoing downloads can be correctly cancelled via thecancel()method, with appropriate state updates (isInProgress, error).timeoutparameter in thedownloadfunction correctly aborts downloads and sets the error state. Tested scenarios both where timeout is exceeded and where download completes before timeout.jsDownloadedge cases: Improved tests forjsDownloadby covering behavior whentempLink.downloadis undefined and ensuringappendChildandremoveChildare correctly called ondocument.body.setErrorCallbackmapping: 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
jsDownloadsetTimeoutduration and theelapsedstate 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.
Describe what's being changed