Skip to main content

Testing Basics

Sonamu uses Vitest.Features:
  • Very fast execution based on Vite
  • Jest-compatible API
  • Native TypeScript support
  • HMR support
Generate with Scaffolding:
  1. Access Sonamu UI
  2. Scaffolding tab
  3. Select Entity
  4. Template: Select model_test
  5. Click Generate
Auto-generated file:

Test Data

setTestData() method:
Using in tests:
Using beforeEach:

Model Testing


API Testing


Advanced Testing


Test Patterns


Best Practices

DO:
  • βœ… Each test should be independently executable
  • βœ… Initialize test data with beforeAll or beforeEach
  • βœ… Use meaningful test names
  • βœ… Test only one feature per test
  • βœ… Always test error cases
DON’T:
  • ❌ Don’t create dependencies between tests
  • ❌ Don’t call real external services (use Mocks)
  • ❌ Don’t use production DB
  • ❌ Avoid hard-coded IDs or dates
  • ❌ Don’t ignore test failures