Suites
A unit-testing framework for TypeScript backend systems working with dependency injection
Works with projects using
NestJSOfficial
InversifyJSOfficial
Vitest
Jest
Sinon- With Suites
- Without Suites
import { TestBed, type Mocked } from '@suites/unit';
describe('User Service', () => {
let userService: UserService; // ๐งช The unit we are testing
let userApi: Mocked<UserApi>; // ๐ญ The dependencies we are mocking
let database: Mocked<Database>;
beforeAll(async () => {
// ๐ Create an isolated test env for the unit
const { unit, unitRef } = await TestBed.solitary(UserService).compile();
userService = unit;
// ๐ Retrieve the unit's dependency mocks - automatically generated
userApi = unitRef.get(UserApi);
database = unitRef.get(Database);
});
// โ
Test test test
it('should generate a random user and save to the database', async () => {
userApi.getRandom.mockResolvedValue({id: 1, name: 'John'} as User);
await userService.generateRandomUser();
expect(database.saveUser).toHaveBeenCalledWith(userFixture);
});
});
import { Test } from '@nestjs/testing';
import { UserService } from './user-service';
import { UserApi } from './user-api';
import { Database } from './database';
describe('User Service', () => {
let userService: UserService;
let userApi: jest.Mocked<UserApi>;
let database: jest.Mocked<Database>;
beforeAll(async () => {
// ๐ง Configure the testing module with all providers
const module = await Test.createTestingModule({
providers: [
UserService,
{ provide: UserApi, useValue: { getRandom: jest.fn() } },
{ provide: Database, useValue: { saveUser: jest.fn() } },
],
}).compile();
userService = module.get<UserService>(UserService);
userApi = module.get(UserApi);
database = module.get(Database);
});
it('should generate a random user and save to the database', async () => {
userApi.getRandom.mockResolvedValue({id: 1, name: 'John'} as User);
await userService.generateRandomUser();
expect(database.saveUser).toHaveBeenCalledWith(userFixture);
});
}
Declarative
An opinionated declarative API: wrap your unit with a single call and receive a correct test environment for testing the unit. No more manual mocking and wiring up dependencies.
Type-Safe
Create type-safe mocks, bound to the implementation and allows calling only the correct dependency methods. No more broken tests after refactors and no more silent failures.
Smart Mock Tracking
Automatically track all dependency methods used during your tests and get notified if a mocked dependency method has no return value or missing mock implementation
AI Ready
With the concise, type safe, and fail-fast format of Suites tests, coding agents (like Claude Code and Cursor) are able to write correct tests in a single pass.
Trusted by
Zero-Setup, Automatic Mocking
Say goodbye to manual mocking. Suites automatically generates mocks for all your dependencies, letting you focus on writing meaningful tests, not boilerplate.
Learn about Mocking โ// No manual mocks needed!
// Just compile the testbed for your class.
const { unit, unitRef } = await TestBed
.solitary(UserService)
.compile();
// Retrieve any dependency as a fully-typed mock.
const userApi = unitRef.get(UserApi);
// Focus on the test logic.
userApi.get.mockResolvedValue({ name: 'John' });
Flexible and Scalable by Design
Whether you're working on a small microservice or a large-scale monolith, Suites' flexible architecture adapts to your needs, ensuring your test suites remain maintainable as your project grows.
Explore Test Strategies โ// Test a class in complete isolation
TestBed.solitary(OrderService).compile();
// Or, test how it integrates with a real dependency
TestBed.sociable(OrderService)
.expose(PaymentProcessor) // Use the real class
.compile();
An Intuitive, Fluent API
Suites provides a clean and semantic API that makes writing tests a pleasure. The intuitive design of the TestBed builder keeps your test code readable and maintainable.
Browse the API Reference โconst { unit, unitRef } = await TestBed
.solitary(ComplexService)
.mock(Logger) // Override with a custom mock
.final({
// Provide custom values or configurations
token: 'API_KEY',
value: 'test-api-key'
})
.compile();