Performance: Unit testing loaders and actions
LOW IMPACT
Unit testing loaders and actions affects development speed and reliability but has minimal direct impact on page load or rendering performance.
import { loader } from './route'; import { mockDatabase } from './mocks'; test('loader returns mocked data', async () => { const context = { params: {}, context: { db: mockDatabase } }; const response = await loader(context); const data = await response.json(); expect(data).toEqual({ user: 'test' }); });
import { loader } from './route'; test('loader returns data', async () => { const response = await loader({ params: {} }); const data = await response.json(); expect(data).toBeDefined(); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Direct loader call without mocks | 0 | 0 | 0 | [X] Bad |
| Loader call with mocked dependencies | 0 | 0 | 0 | [OK] Good |