Skip to content

Restore global.fetch after each test. #46

@AStevensTaylor

Description

@AStevensTaylor

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

cat -n src/components/GifFrameExtractor.test.tsx

Repository: AStevensTaylor/image-tools

Length of output: 13605


Restore global.fetch after each test.

Multiple tests mock global.fetch without restoration, causing test isolation issues. Later tests will inherit the previous test's stub instead of the real fetch. Store originalFetch at module level and restore it in the existing afterEach hook, following the pattern already used for ImageDecoder restoration in this file.

Proposed fix
+const originalFetch = global.fetch;
+
 beforeEach(() => {
 	localStorage.clear();
 });

 afterEach(() => {
 	localStorage.clear();
+	global.fetch = originalFetch;
 });
🤖 Prompt for AI Agents
In `@src/components/GifFrameExtractor.test.tsx` around lines 8 - 14, Store the
original global.fetch in a module-level variable (e.g. originalFetch) before
tests run and restore it in the existing afterEach hook alongside the
ImageDecoder cleanup; modify the test file so before any test stubs replace
global.fetch you assign originalFetch = global.fetch, and update afterEach() to
set global.fetch = originalFetch (and then clear localStorage as currently done)
to ensure fetch is restored between tests.

Originally posted by @coderabbitai[bot] in #44 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions