Not everything needs a test. Focus on what provides value.
ā DO Test
Business Logic
javascript// ā Test: Complex calculations test('applies discount correctly', () => { const order = new Order({ subtotal: 100 }); order.applyDiscount('SAVE20'); expect(order.total).toBe(80); });
User Interactions
javascript// ā Test: Form submission works test('submits form with data', async () => { const { getByLabelText, getByRole } = render(ContactForm); await fireEvent.input(getByLabelText('Email'), { target: { value: 'test@example.com' }}); await fireEvent.click(getByRole('button', { name: 'Submit' })); // Assert form was submitted });
Edge Cases
javascript// ā Test: Empty state, errors, boundaries test('shows empty state when no items', () => { const { getByText } = render(ItemList, { props: { items: [] }}); expect(getByText('No items yet')).toBeInTheDocument(); });
Accessibility
javascript// ā Test: Keyboard navigation works test('can navigate with keyboard', async () => { const { getByRole } = render(Dropdown); await fireEvent.keyDown(getByRole('button'), { key: 'ArrowDown' }); expect(getByRole('option', { name: 'First' })).toHaveFocus(); });
ā DON'T Test
Implementation Details
javascript// ā Don't test internal state names test('sets isLoading to true', () => { // Testing internal state, not behavior }); // ā Test behavior instead test('shows loading spinner during fetch', async () => { const { getByRole } = render(DataLoader); expect(getByRole('progressbar')).toBeInTheDocument(); });
Framework Features
javascript// ā Don't test that Svelte's reactivity works test('$state updates component', () => { // Svelte already tests this! });
Third-Party Code
javascript// ā Don't test libraries you don't own test('fetch returns JSON', () => { // Test YOUR code that uses fetch });
š What to test