test(web): import history components after their mocks (M494)
HistoryRow now renders LikeButton, and both history test files imported the component before the likes mock helper. LikeButton then loaded while emptyLikesMock was still uninitialised, and the suites failed at import. Every other suite imports components after its mocks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
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 HistoryRow from './HistoryRow.svelte';
|
|
||||||
import type { HistoryEvent } from '#lib/api/history.js';
|
import type { HistoryEvent } from '#lib/api/history.js';
|
||||||
import { makeTrack } from '#test-utils/fixtures/track.js';
|
import { makeTrack } from '#test-utils/fixtures/track.js';
|
||||||
import { emptyLikesMock } from '../../test-utils/mocks/likes';
|
import { emptyLikesMock } from '../../test-utils/mocks/likes';
|
||||||
@@ -27,6 +26,10 @@ vi.mock('#lib/api/likes.js', () => emptyLikesMock());
|
|||||||
|
|
||||||
vi.mock('#lib/api/quarantine.js', () => emptyQuarantineMock());
|
vi.mock('#lib/api/quarantine.js', () => emptyQuarantineMock());
|
||||||
|
|
||||||
|
// Imported after the mocks: the component pulls in LikeButton, whose
|
||||||
|
// mocked module must already be initialised.
|
||||||
|
import HistoryRow from './HistoryRow.svelte';
|
||||||
|
|
||||||
const sampleTrack = makeTrack({
|
const sampleTrack = makeTrack({
|
||||||
title: 'Song Title',
|
title: 'Song Title',
|
||||||
album_title: 'Album',
|
album_title: 'Album',
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||||
import { render, screen } from '@testing-library/svelte';
|
import { render, screen } from '@testing-library/svelte';
|
||||||
import HistoryPage from './+page.svelte';
|
|
||||||
import type { HistoryEvent, HistoryResponse } from '#lib/api/history.js';
|
import type { HistoryEvent, HistoryResponse } from '#lib/api/history.js';
|
||||||
import { makeTrack } from '#test-utils/fixtures/track.js';
|
import { makeTrack } from '#test-utils/fixtures/track.js';
|
||||||
import { emptyLikesMock } from '../../../test-utils/mocks/likes';
|
import { emptyLikesMock } from '../../../test-utils/mocks/likes';
|
||||||
@@ -63,6 +62,10 @@ vi.mock('#lib/branding.js', () => ({
|
|||||||
pageTitle: (s: string) => `Minstrel · ${s}`
|
pageTitle: (s: string) => `Minstrel · ${s}`
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Imported after the mocks: the component pulls in LikeButton, whose
|
||||||
|
// mocked module must already be initialised.
|
||||||
|
import HistoryPage from './+page.svelte';
|
||||||
|
|
||||||
describe('library/history page', () => {
|
describe('library/history page', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockData = { pages: [] };
|
mockData = { pages: [] };
|
||||||
|
|||||||
Reference in New Issue
Block a user