mirror of
https://github.com/hcengineering/platform.git
synced 2026-08-30 03:39:39 +02:00
* Drawing board colors palette now depends on UI color theme Signed-off-by: Denis Gladkiy <denis.gladkiy@hardcoreeng.com> * Desktop app for windows bug fixes. Formatting and style fixes. Signed-off-by: Denis Gladkiy <denis.gladkiy@hardcoreeng.com> * Desktop app bug fix. Signed-off-by: Denis Gladkiy <denis.gladkiy@hardcoreeng.com> * Theme unsubscribing fix. Signed-off-by: Denis Gladkiy <denis.gladkiy@hardcoreeng.com> * Formatting. Signed-off-by: Denis Gladkiy <denis.gladkiy@hardcoreeng.com> * Typo fix. Signed-off-by: Denis Gladkiy <denis.gladkiy@hardcoreeng.com> --------- Signed-off-by: Denis Gladkiy <denis.gladkiy@hardcoreeng.com>
Svelte Testing Strategy
This project uses an enhanced mocking approach for Svelte components and stores in Jest tests, inspired by Svelte Testing Library patterns but adapted for our current Jest setup.
Current Approach: Enhanced Svelte Mocking
What We Have
- Robust Svelte Store Mocks: Our
svelte-store.jsmock provides functional implementations ofwritable,derived, andreadablestores with testing helpers - Complete Svelte Ecosystem Coverage: Mocks for
svelte,svelte/transition,svelte/animate, and.sveltecomponents - Jest Integration: Works seamlessly with our existing Jest configuration without requiring ESM mode
Benefits
- ✅ Simple Setup: No complex ESM configuration required
- ✅ Fast Tests: Lightweight mocks don't slow down test execution
- ✅ Focused Testing: Tests logic rather than UI components
- ✅ Backward Compatible: Works with existing Jest setup
When This Approach Works Best
- Testing business logic that uses Svelte stores
- Testing utility functions that depend on Svelte ecosystem
- Integration tests that need to mock Svelte dependencies
- When you don't need to test actual Svelte component rendering
Future: Migration to Svelte Testing Library
When to Consider Migration
Consider migrating to full Svelte Testing Library when you need to:
- Test Svelte Components: Render and interact with actual
.sveltecomponents - Test User Interactions: Simulate clicks, form inputs, etc. on Svelte components
- Test Component Props: Verify how components respond to different prop values
- Test Component Events: Verify custom event dispatching
Migration Steps (Future)
If you need full Svelte Testing Library support:
-
Install Dependencies:
npm install --save-dev @testing-library/svelte svelte-jester jest-environment-jsdom -
Update Jest Configuration to ESM mode:
export default { transform: { '^.+\\.svelte(\\.(js|ts))?$': 'svelte-jester', }, transformIgnorePatterns: [ '/node_modules/(?!@testing-library/svelte/)', ], moduleFileExtensions: ['js', 'svelte', 'ts'], extensionsToTreatAsEsm: ['.svelte'], testEnvironment: 'jsdom', setupFilesAfterEnv: ['<rootDir>/jest-setup.js'], } -
Update Package.json scripts:
{ "scripts": { "test": "npx --node-options=\"--experimental-vm-modules\" jest src" } }
Example Test with Svelte Testing Library
import { render, screen, fireEvent } from '@testing-library/svelte'
import MyComponent from './MyComponent.svelte'
test('renders and handles click', async () => {
render(MyComponent, { props: { title: 'Hello' } })
const button = screen.getByRole('button')
await fireEvent.click(button)
expect(screen.getByText('Clicked!')).toBeInTheDocument()
})
Current Mock Files
__mocks__/svelte-store.js
- Functional implementations of Svelte stores
- Testing helpers like
_getValue()andget() - Proper subscriber management
__mocks__/svelte.js
- Core Svelte lifecycle functions (
onMount,onDestroy) - Utility functions (
tick,createEventDispatcher)
__mocks__/svelte-component.js
- Mock for
.sveltefiles - Returns simple DOM element for component imports
__mocks__/svelte-transition.js & __mocks__/svelte-animate.js
- Animation and transition function mocks
- Return basic CSS transformation objects
Best Practices
- Use Store Testing Helpers: Leverage
_getValue()for easy store value assertions - Focus on Logic: Test business logic, not UI rendering details
- Mock Appropriately: Only mock what you need to avoid test complexity
- Consider Migration: Plan for Svelte Testing Library when component testing becomes necessary
Example Usage
import { get } from '../__mocks__/svelte-store.js'
test('store behavior', () => {
const store = writable(0)
store.set(5)
expect(get(store)).toBe(5)
expect(store._getSubscriberCount()).toBe(0)
})