Enhance Vitest configuration and improve Vue integration

- Added Vue plugin to vitest.config.ts for better component testing.
- Introduced vitest.setup.ts to expose Vue reactivity and lifecycle methods globally, ensuring compatibility with .vue components.
- Updated mock implementations in nuxt-imports.ts to include readonly for improved reactivity handling.
- Refactored useMapBookmarks and useToast composables to utilize readonly from Vue for better state management.
This commit is contained in:
2026-03-04 14:12:48 +03:00
parent fd624c2357
commit 337386caa8
7 changed files with 75 additions and 15 deletions

View File

@@ -4,29 +4,36 @@ import type L from 'leaflet'
import type { Map, LayerGroup } from 'leaflet'
import { createCharacter, type CharacterData, type CharacterMapViewRef } from '../Character'
vi.mock('leaflet', () => {
const { leafletMock } = vi.hoisted(() => {
const markerMock = {
on: vi.fn().mockReturnThis(),
addTo: vi.fn().mockReturnThis(),
setLatLng: vi.fn().mockReturnThis(),
setIcon: vi.fn().mockReturnThis(),
}
return {
default: {
marker: vi.fn(() => markerMock),
Icon: vi.fn().mockImplementation(() => ({})),
},
const Icon = vi.fn().mockImplementation(function (this: unknown) {
return {}
})
const L = {
marker: vi.fn(() => markerMock),
Icon: vi.fn().mockImplementation(() => ({})),
Icon,
}
return { leafletMock: L }
})
vi.mock('leaflet', () => ({
__esModule: true,
default: leafletMock,
marker: leafletMock.marker,
Icon: leafletMock.Icon,
}))
vi.mock('~/lib/LeafletCustomTypes', () => ({
HnHMaxZoom: 6,
}))
function getL(): L {
return require('leaflet').default
return leafletMock as unknown as L
}
function makeCharData(overrides: Partial<CharacterData> = {}): CharacterData {