API Reference
Complete API reference for Suites testing framework
API reference for setting up and managing unit tests with Suites.
Core APIs
- TestBed.solitary() - Create isolated unit tests where all dependencies are automatically mocked
- TestBed.sociable() - Test business logic interactions, keep specific dependencies real
- Mock Configuration - Configure mock behavior with
.mock().final()and.mock().impl() - mock() and stub() - Create standalone mocks outside
TestBedAPI - UnitReference - Access mocked dependencies in tests
- Types - TypeScript type definitions
Quick Reference
Creating a Solitary Test
const { unit, unitRef } = await TestBed.solitary(UserService).compile();Creating a Sociable Test
const { unit, unitRef } = await TestBed.sociable(UserService) .expose(UserApi) // Keep UserApi real .compile();Configuring Mocks
// Final configuration (immutable)await TestBed.solitary(UserService) .mock(UserApi) .final({ getRandom: async () => ({ id: 1, name: 'John' }) }) .compile();
// Flexible configurationawait TestBed.solitary(UserService) .mock(UserApi) .impl(stubFn => ({ getRandom: stubFn().mockResolvedValue({ id: 1 }) })) .compile();Creating Standalone Mocks
import { mock, stub } from '@suites/unit';
// Mock a full classconst userRepo = mock<UserRepository>();userRepo.findById.mockResolvedValue(testUser);
// Create a stub functionconst stubFn = stub();stubFn.mockReturnValue(42);Quick Terminology
- Mock: A complete replacement of a dependency class where each method has been replaced with a stub
- Stub: An individual method replacement that provides predefined responses
- Mocked<T>: The type representing a mocked dependency with stubbed methods