Skip to main content

Testing Reatom Code

Reatom’s architecture makes testing straightforward and predictable. Test your state logic in isolation without complex mocking or framework-specific testing utilities.

Core Testing Principles

Reatom enables effective testing through:
  • Isolation - Test atoms and actions independently
  • Determinism - Pure computations produce predictable results
  • Synchronous Testing - Most tests run synchronously
  • No Mocking - Test real implementations
  • Framework Agnostic - Works with any test runner

Quick Start

Basic Atom Test

Action Test

Testing Computed Atoms

Basic Computed

Memoization Test

Testing Async Operations

Async Actions

Testing withAsyncData

Error Handling

Testing Forms

Field Validation

Form Submission

Schema Validation

Testing Routing

Route Matching

Route Loaders

Testing Persistence

LocalStorage Persistence

Memory Storage for Tests

Mocking Dependencies

Mock API Calls

Dependency Injection

Testing Side Effects

Effect Testing

Hook Testing

Best Practices

1. Test Behavior, Not Implementation

2. Use Real Implementations

3. Clean Up After Tests

4. Test Edge Cases

5. Use Descriptive Test Names

Common Patterns

Snapshot Testing

Parameterized Tests

Integration Tests