From d13a5b2113b05cdfd7719b65c33e20a8f7bb63bd Mon Sep 17 00:00:00 2001 From: nitrix Date: Mon, 20 Apr 2026 22:42:51 +0200 Subject: [PATCH] Add type parameters to vi.fn() mocks for oxlint 1.60 vitest rule oxlint 1.60 enables vitest/require-mock-type-parameters by default, which requires explicit type parameters on all vi.fn() calls. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../components/__tests__/EventList.spec.ts | 7 ++-- .../views/__tests__/EventCreateView.spec.ts | 33 ++++++++++--------- .../views/__tests__/EventDetailView.spec.ts | 24 +++++++------- .../src/views/__tests__/EventStubView.spec.ts | 4 +-- 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/frontend/src/components/__tests__/EventList.spec.ts b/frontend/src/components/__tests__/EventList.spec.ts index e449807..e93d200 100644 --- a/frontend/src/components/__tests__/EventList.spec.ts +++ b/frontend/src/components/__tests__/EventList.spec.ts @@ -2,11 +2,12 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest' import { mount, flushPromises } from '@vue/test-utils' import { createRouter, createMemoryHistory } from 'vue-router' import EventList from '../EventList.vue' +import type { api } from '../../api/client' vi.mock('../../api/client', () => ({ api: { - PATCH: vi.fn(), - DELETE: vi.fn(), + PATCH: vi.fn(), + DELETE: vi.fn(), }, })) @@ -31,7 +32,7 @@ const mockEvents = [ { eventToken: 'rsvp-1', title: 'Attending Event', dateTime: '2026-03-11T20:00:00', rsvpToken: 'rsvp-token', rsvpName: 'Max' }, ] -const removeEventMock = vi.fn() +const removeEventMock = vi.fn<(eventToken: string) => void>() vi.mock('../../composables/useEventStorage', () => ({ isValidStoredEvent: (e: unknown) => { diff --git a/frontend/src/views/__tests__/EventCreateView.spec.ts b/frontend/src/views/__tests__/EventCreateView.spec.ts index 3aaeb72..edea6fb 100644 --- a/frontend/src/views/__tests__/EventCreateView.spec.ts +++ b/frontend/src/views/__tests__/EventCreateView.spec.ts @@ -3,19 +3,20 @@ import { mount, flushPromises } from '@vue/test-utils' import { createRouter, createMemoryHistory } from 'vue-router' import EventCreateView from '../EventCreateView.vue' import { api } from '@/api/client' +import type { StoredEvent } from '@/composables/useEventStorage' vi.mock('@/api/client', () => ({ api: { - POST: vi.fn(), + POST: vi.fn(), }, })) vi.mock('@/composables/useEventStorage', () => ({ - useEventStorage: vi.fn(() => ({ - saveCreatedEvent: vi.fn(), - getStoredEvents: vi.fn(() => []), - getOrganizerToken: vi.fn(), - saveRsvp: vi.fn(), - getRsvp: vi.fn(), + useEventStorage: vi.fn<() => unknown>(() => ({ + saveCreatedEvent: vi.fn<() => void>(), + getStoredEvents: vi.fn<() => unknown[]>(() => []), + getOrganizerToken: vi.fn<() => string | undefined>(), + saveRsvp: vi.fn<() => void>(), + getRsvp: vi.fn<() => unknown>(), })), })) @@ -154,19 +155,19 @@ describe('EventCreateView', () => { }) it('submits successfully, saves to storage, and navigates to event page', async () => { - const mockSave = vi.fn() + const mockSave = vi.fn<(...args: unknown[]) => void>() vi.mocked(vi.importActual) const { useEventStorage } = await import('@/composables/useEventStorage') vi.mocked(useEventStorage).mockReturnValue({ saveCreatedEvent: mockSave, - getStoredEvents: vi.fn(() => []), - getOrganizerToken: vi.fn(), - saveRsvp: vi.fn(), - getRsvp: vi.fn(), - removeRsvp: vi.fn(), - saveWatch: vi.fn(), - isStored: vi.fn(() => false), - removeEvent: vi.fn(), + getStoredEvents: vi.fn<() => StoredEvent[]>(() => []), + getOrganizerToken: vi.fn<() => string | undefined>(), + saveRsvp: vi.fn<() => void>(), + getRsvp: vi.fn<() => { rsvpToken: string; rsvpName: string } | undefined>(), + removeRsvp: vi.fn<() => void>(), + saveWatch: vi.fn<() => void>(), + isStored: vi.fn<() => boolean>(() => false), + removeEvent: vi.fn<() => void>(), }) vi.mocked(api.POST).mockResolvedValueOnce({ diff --git a/frontend/src/views/__tests__/EventDetailView.spec.ts b/frontend/src/views/__tests__/EventDetailView.spec.ts index b0deb5d..2580623 100644 --- a/frontend/src/views/__tests__/EventDetailView.spec.ts +++ b/frontend/src/views/__tests__/EventDetailView.spec.ts @@ -6,26 +6,26 @@ import { api } from '@/api/client' vi.mock('@/api/client', () => ({ api: { - GET: vi.fn(), - POST: vi.fn(), + GET: vi.fn(), + POST: vi.fn(), }, })) -const mockSaveRsvp = vi.fn() -const mockGetRsvp = vi.fn() -const mockGetOrganizerToken = vi.fn() -const mockSaveWatch = vi.fn() -const mockIsStored = vi.fn() -const mockRemoveEvent = vi.fn() +const mockSaveRsvp = vi.fn<(...args: unknown[]) => void>() +const mockGetRsvp = vi.fn<(eventToken: string) => { rsvpToken: string; rsvpName: string } | undefined>() +const mockGetOrganizerToken = vi.fn<(eventToken: string) => string | undefined>() +const mockSaveWatch = vi.fn<(...args: unknown[]) => void>() +const mockIsStored = vi.fn<(eventToken: string) => boolean>() +const mockRemoveEvent = vi.fn<(eventToken: string) => void>() vi.mock('@/composables/useEventStorage', () => ({ - useEventStorage: vi.fn(() => ({ - saveCreatedEvent: vi.fn(), - getStoredEvents: vi.fn(() => []), + useEventStorage: vi.fn<() => unknown>(() => ({ + saveCreatedEvent: vi.fn<() => void>(), + getStoredEvents: vi.fn<() => unknown[]>(() => []), getOrganizerToken: mockGetOrganizerToken, saveRsvp: mockSaveRsvp, getRsvp: mockGetRsvp, - removeRsvp: vi.fn(), + removeRsvp: vi.fn<() => void>(), saveWatch: mockSaveWatch, isStored: mockIsStored, removeEvent: mockRemoveEvent, diff --git a/frontend/src/views/__tests__/EventStubView.spec.ts b/frontend/src/views/__tests__/EventStubView.spec.ts index 528cc59..1375833 100644 --- a/frontend/src/views/__tests__/EventStubView.spec.ts +++ b/frontend/src/views/__tests__/EventStubView.spec.ts @@ -46,7 +46,7 @@ describe('EventStubView', () => { }) it('copies link to clipboard and shows confirmation', async () => { - const writeTextMock = vi.fn().mockResolvedValue(undefined) + const writeTextMock = vi.fn<(text: string) => Promise>().mockResolvedValue(undefined) Object.assign(navigator, { clipboard: { writeText: writeTextMock }, }) @@ -63,7 +63,7 @@ describe('EventStubView', () => { it('shows failure message when clipboard is unavailable', async () => { Object.assign(navigator, { - clipboard: { writeText: vi.fn().mockRejectedValue(new Error('Not allowed')) }, + clipboard: { writeText: vi.fn<(text: string) => Promise>().mockRejectedValue(new Error('Not allowed')) }, }) const wrapper = await mountWithToken('fail-test')