Performance: Unit testing logic
LOW IMPACT
Unit testing logic affects development speed and feedback loop but does not impact page load or rendering performance directly.
import { describe, it, expect } from 'vitest'; import { myLogicFunction } from './myLogic.js'; // Test logic directly without rendering describe('myLogicFunction', () => { it('returns correct result', () => { expect(myLogicFunction(5)).toBe(10); }); });
import { render } from '@testing-library/svelte'; import { test, expect } from 'vitest'; import MyComponent from './MyComponent.svelte'; // Test that relies on full DOM rendering test('checks logic by rendering full component', () => { const { getByText } = render(MyComponent); expect(getByText('Hello')).toBeInTheDocument(); // Additional logic tests done via DOM queries });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Testing logic via full component render | Many DOM nodes created | Multiple reflows triggered | High paint cost due to rendering | [X] Bad |
| Testing logic via direct function calls | No DOM nodes | No reflows | No paint cost | [OK] Good |