mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-19 13:21:46 +00:00
fix(tests): target window.URL instead of URL for createObjectURL mocking
In jsdom, source modules resolve bare 'URL' identifiers through window.URL (the jsdom window object), not through globalThis.URL (Node's URL class). On GitHub Actions these are distinct objects, so all prior attempts (Object.defineProperty, direct assignment, vi.stubGlobal) were patching the wrong object and failing silently. Changes: - setup.ts: Object.defineProperty targets window.URL so the vi.fn mock is visible to authUrl.ts at call time - authUrl.test.ts: drop vi.stubGlobal approach; add vi.clearAllMocks() to reset accumulated call counts on the setup.ts vi.fn between tests; fix vi.spyOn target to window.URL in test 012
This commit is contained in:
@@ -59,10 +59,11 @@ globalThis.ResizeObserver = vi.fn().mockImplementation(() => ({
|
||||
disconnect: vi.fn(),
|
||||
})) as unknown as typeof ResizeObserver;
|
||||
|
||||
// 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() });
|
||||
// URL.createObjectURL / revokeObjectURL — in jsdom, modules access globals
|
||||
// through window.URL (not globalThis.URL — these are different objects on CI).
|
||||
// Targeting window.URL is required so the mock is visible to source modules.
|
||||
Object.defineProperty(window.URL, 'createObjectURL', { writable: true, configurable: true, value: vi.fn(() => 'blob:mock') });
|
||||
Object.defineProperty(window.URL, 'revokeObjectURL', { writable: true, configurable: true, value: vi.fn() });
|
||||
|
||||
// Element.prototype.scrollIntoView — jsdom doesn't implement it
|
||||
Element.prototype.scrollIntoView = vi.fn();
|
||||
|
||||
Reference in New Issue
Block a user