Performance: Component testing with Testing Library
LOW IMPACT
Component testing affects development speed and feedback loop but can indirectly impact page load speed by encouraging better code practices.
import { render, fireEvent, screen } from '@testing-library/svelte'; import MyComponent from './MyComponent.svelte'; test('button click updates text', async () => { render(MyComponent); const button = screen.getByRole('button', { name: /click me/i }); await fireEvent.click(button); expect(screen.getByText(/clicked/i)).toBeInTheDocument(); });
import { render } from '@testing-library/svelte'; import MyComponent from './MyComponent.svelte'; // Testing by querying DOM nodes directly and manipulating them const { container } = render(MyComponent); const button = container.querySelector('button'); button.click(); // No assertions or indirect testing
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Direct DOM queries and manipulation in tests | High (many queries) | N/A | N/A | [X] Bad |
| Using Testing Library queries and fireEvent | Minimal and targeted | N/A | N/A | [OK] Good |