Skip to main content
Orionjs uses Vitest for testing. This guide covers setup, conventions, and best practices.

Installation

For MongoDB testing:

Configuration

Create a vitest.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 test
  • mockX - Mocked dependencies
  • actualX - The actual result from the code under test
  • expectedX - 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

Use mockService from @orion-js/services to mock dependencies:

Best Practices

  1. Use test doubles for dependencies - Except for third-party dependencies that are not expensive to execute
  2. Keep tests isolated - Each test should be independent and not rely on state from other tests
  3. Test behavior, not implementation - Focus on what the code does, not how it does it
  4. Use descriptive test names - Test names should describe the scenario being tested
  5. Don’t mock data for dev or prod - Mocking data is only for tests

Running Tests