fix(tests): resolve URL.createObjectURL and fetch mocking failures on CI

Three interrelated issues caused 4 tests to pass locally but fail on CI:

1. setup.ts only applied the URL.createObjectURL stub when it was
   undefined, but jsdom already defines it (returning ''). Changed to
   always override with configurable:true so the predictable 'blob:mock'
   value is set in every environment.

2. FE-API-013 used Object.defineProperty (non-configurable in jsdom) and
   MSW to handle a native fetch call. Replaced with vi.spyOn for both
   URL.createObjectURL/revokeObjectURL and a direct fetch mock, which is
   more reliable across environments.

3. FE-COMP-AUTHURL-012's vi.spyOn(URL, 'createObjectURL') returned the
   same vi.fn() instance set in setup.ts, accumulating calls from all
   prior tests in the file (1+8+7+6=22 instead of 6). Added mockClear()
   immediately after the spy setup to reset the count.
This commit is contained in:
jubnl
2026-04-07 22:51:19 +02:00
parent 9e23766b51
commit d8da0fffa5
3 changed files with 13 additions and 17 deletions
+4 -7
View File
@@ -59,13 +59,10 @@ globalThis.ResizeObserver = vi.fn().mockImplementation(() => ({
disconnect: vi.fn(),
})) as unknown as typeof ResizeObserver;
// URL.createObjectURL / revokeObjectURL — used by file uploads
if (typeof URL.createObjectURL === 'undefined') {
Object.defineProperty(URL, 'createObjectURL', { writable: true, value: vi.fn(() => 'blob:mock') });
}
if (typeof URL.revokeObjectURL === 'undefined') {
Object.defineProperty(URL, 'revokeObjectURL', { writable: true, value: vi.fn() });
}
// URL.createObjectURL / revokeObjectURL — jsdom defines these but returns '' for createObjectURL;
// always override so tests get a predictable 'blob:mock' string.
Object.defineProperty(URL, 'createObjectURL', { writable: true, configurable: true, value: vi.fn(() => 'blob:mock') });
Object.defineProperty(URL, 'revokeObjectURL', { writable: true, configurable: true, value: vi.fn() });
// Element.prototype.scrollIntoView — jsdom doesn't implement it
Element.prototype.scrollIntoView = vi.fn();