fix(test): order likes mock before component import in queue tests — #1596
test-web / test (push) Successful in 36s
test-web / test (push) Successful in 36s
The prior test fix registered the emptyLikesMock stub but imported it (and the component under test) in the wrong order: importing QueueTrackRow / QueueDrawer transitively loads LikeButton → the mocked $lib/api/likes, whose hoisted factory runs before the emptyLikesMock import initialized — "Cannot access '__vi_import_N__' before initialization". Move the emptyLikesMock import above, and the component import below, the vi.mock call — matching the ArtistMenu/PlayerBar test layout so the factory's binding is ready when the component graph loads. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,15 @@
|
|||||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||||
import { render, screen, fireEvent } from '@testing-library/svelte';
|
import { render, screen, fireEvent } from '@testing-library/svelte';
|
||||||
import QueueDrawer from './QueueDrawer.svelte';
|
import { emptyLikesMock } from '../../test-utils/mocks/likes';
|
||||||
import type { TrackRef } from '$lib/api/types';
|
import type { TrackRef } from '$lib/api/types';
|
||||||
import { makeTrack } from '$test-utils/fixtures/track';
|
import { makeTrack } from '$test-utils/fixtures/track';
|
||||||
import { emptyLikesMock } from '../../test-utils/mocks/likes';
|
|
||||||
|
|
||||||
// QueueTrackRow (rendered inside QueueDrawer → QueueList) now renders a
|
// QueueTrackRow (rendered inside QueueDrawer → QueueList) now renders a
|
||||||
// LikeButton, which reads createLikedIdsQuery. Stub the likes API so the
|
// LikeButton, which reads createLikedIdsQuery. Stub the likes API so the
|
||||||
// rows don't need a real QueryClient in context.
|
// rows don't need a real QueryClient in context. Both mocks — and the
|
||||||
|
// emptyLikesMock import — must precede the QueueDrawer import below, since
|
||||||
|
// loading the component evaluates the mocked modules and the hoisted
|
||||||
|
// factories need their referenced bindings already initialized.
|
||||||
vi.mock('$lib/api/likes', () => emptyLikesMock());
|
vi.mock('$lib/api/likes', () => emptyLikesMock());
|
||||||
|
|
||||||
const closeQueueDrawer = vi.fn();
|
const closeQueueDrawer = vi.fn();
|
||||||
@@ -29,6 +31,8 @@ vi.mock('$lib/player/store.svelte', () => ({
|
|||||||
moveQueueItem: vi.fn()
|
moveQueueItem: vi.fn()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
import QueueDrawer from './QueueDrawer.svelte';
|
||||||
|
|
||||||
const t = (id: string): TrackRef => makeTrack({ id, title: `Song ${id}` });
|
const t = (id: string): TrackRef => makeTrack({ id, title: `Song ${id}` });
|
||||||
|
|
||||||
describe('QueueDrawer', () => {
|
describe('QueueDrawer', () => {
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||||
import { render, screen, fireEvent } from '@testing-library/svelte';
|
import { render, screen, fireEvent } from '@testing-library/svelte';
|
||||||
import QueueTrackRow from './QueueTrackRow.svelte';
|
|
||||||
import { makeTrack } from '$test-utils/fixtures/track';
|
|
||||||
import { emptyLikesMock } from '../../test-utils/mocks/likes';
|
import { emptyLikesMock } from '../../test-utils/mocks/likes';
|
||||||
|
import { makeTrack } from '$test-utils/fixtures/track';
|
||||||
|
|
||||||
// QueueTrackRow now renders a LikeButton, which reads createLikedIdsQuery.
|
// QueueTrackRow now renders a LikeButton, which reads createLikedIdsQuery.
|
||||||
// Stub the likes API so the row doesn't need a real QueryClient in context.
|
// Stub the likes API so the row doesn't need a real QueryClient in context.
|
||||||
|
// The mock (and its emptyLikesMock import) must precede the component import
|
||||||
|
// below: importing QueueTrackRow transitively loads LikeButton → the mocked
|
||||||
|
// module, and the hoisted factory needs emptyLikesMock already initialized.
|
||||||
vi.mock('$lib/api/likes', () => emptyLikesMock());
|
vi.mock('$lib/api/likes', () => emptyLikesMock());
|
||||||
|
|
||||||
|
import QueueTrackRow from './QueueTrackRow.svelte';
|
||||||
|
|
||||||
const playFromQueueIndex = vi.fn();
|
const playFromQueueIndex = vi.fn();
|
||||||
const removeFromQueue = vi.fn();
|
const removeFromQueue = vi.fn();
|
||||||
const moveQueueItem = vi.fn();
|
const moveQueueItem = vi.fn();
|
||||||
|
|||||||
Reference in New Issue
Block a user