Installation
Configuration
Create avitest.config.ts file in your project root:
Setup File
Create a./app/config/tests/setup.ts file:
Test Conventions
Arrange-Act-Assert Pattern
Follow the AAA pattern for all tests:Variable Naming Convention
Use clear, consistent variable names:inputX- Input data for the testmockX- Mocked dependenciesactualX- The actual result from the code under testexpectedX- The expected result to compare against
Unit Tests
Write unit tests for each service function using test doubles to simulate dependencies:Acceptance Tests
Write acceptance tests for each module following the Given-When-Then convention:Mocking Services
UsemockService from @orion-js/services to mock dependencies:
Best Practices
- Use test doubles for dependencies - Except for third-party dependencies that are not expensive to execute
- Keep tests isolated - Each test should be independent and not rely on state from other tests
- Test behavior, not implementation - Focus on what the code does, not how it does it
- Use descriptive test names - Test names should describe the scenario being tested
- Don’t mock data for dev or prod - Mocking data is only for tests