-
Notifications
You must be signed in to change notification settings - Fork 0
Testing
Göktürk edited this page Feb 5, 2025
·
1 revision
We are currently in the process of implementing the testing workflow for this project. This document provides a general overview of the testing strategy and debugging tools that will be used.
This project includes unit and integration testing using Vitest, along with debugging tools integrated into the development workflow. Testing ensures the stability of components, API integrations, and state management.
- Vitest – Unit and integration testing framework for Vue 3.
- Vue Test Utils – Provides utilities for testing Vue components.
- Pinia Testing Utilities – Mocking and testing state management.
- Vue DevTools – Debugging Vue components and Pinia state.
Test files are located alongside the respective components or inside a tests/
directory.
📂 tests
┣ 📜 components.test.ts # Unit tests for Vue components
┣ 📜 store.test.ts # Pinia store tests
┣ 📜 api.test.ts # API integration tests
import { mount } from '@vue/test-utils';
import BaseSidebarComponent from '@/components/Base/BaseSidebarComponent.vue';
describe('BaseSidebarComponent', () => {
it('renders the sidebar correctly', () => {
const wrapper = mount(BaseSidebarComponent);
expect(wrapper.exists()).toBe(true);
});
});
import { setActivePinia, createPinia } from 'pinia';
import { useMapStore } from '@/store/map';
describe('Map Store', () => {
beforeEach(() => {
setActivePinia(createPinia());
});
it('updates the zoom level', () => {
const mapStore = useMapStore();
mapStore.setZoom(12);
expect(mapStore.zoom).toBe(12);
});
});
import { vi } from 'vitest';
import { getActiveCampaigns } from '@/store/participation';
global.fetch = vi.fn(() => Promise.resolve({
json: () => Promise.resolve([{ id: 1, name: 'Campaign 1' }])
}));
describe('API Calls', () => {
it('fetches active campaigns', async () => {
const campaigns = await getActiveCampaigns();
expect(campaigns.length).toBe(1);
});
});
- Inspect Vue components and their state.
- View and modify Pinia store data in real-time.
To debug API responses, log data in the console before processing:
async function fetchData() {
const response = await fetch('/api/data');
const data = await response.json();
console.log('API Response:', data);
}
-
Blank Component Output? Ensure
props
are passed correctly. - State Not Updating? Check if mutations are triggering properly.
- API Errors? Log responses and verify request payloads.
For detailed testing strategies, refer to Vitest and Vue Test Utils documentation.
Welcome to the TOSCA Wiki! You'll find both user and developer documentation here.