Skip to main content
Sonamu automatically generates model test files with the pnpm generate command.

Scaffolding Overview

Auto Generation

model.test.ts creation Basic structure included

Bootstrap Included

Auto test environment setup Immediately executable

CRUD Tests

Basic test skeleton Customizable

Type Safe

Model integration Auto-completion support

Test File Generation

Command

When an Entity is defined, {model}.test.ts files are automatically generated. Generation location:

Generated File Structure

Running Tests

Run Single File

Run All Tests

Watch Mode

Test Writing Guide

CRUD Test Pattern

Relationship Tests

Error Tests

Structuring Tests

Grouping Multiple Tests

Best Practices

1. Test Isolation

Each test should run independently.

2. Clear Test Names

3. Arrange-Act-Assert Pattern

Cautions

Cautions when writing tests: 1. Don’t modify auto-generated files: Will be overwritten on regeneration 2. Independent tests: No dependencies between tests 3. Transaction based: Auto rollback after each test 4. Async required: All tests must be async functions 5. Clear names: Clearly state what the test verifies

Next Steps

Test Structure

bootstrap, test, testAs

Test Helpers

Fixtures and utilities

Vitest Docs

Vitest guide

Model System

Understanding Models