You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unit testing framework for dependency injection that automates mocking and simplifies test setup, reducing boilerplate code and enabling developers to build comprehensive and reliable test suites with a standardized, type-safe API
Suites is a progressive, flexible unit-testing framework aimed at elevating the software testing experience within
backend systems working with dependency injection frameworks.
Suites provides a unified testing experience that combines best practices, industry standards, and a wide range of
testing tools to help developers create robust, maintainable, and scalable test suites, thereby ensuring the development
of high-quality software.
Are you using Suites in your projects? We've created a community discussion where teams and companies can share how they're using Suites in production.
Suites offers an alternative approach to writing unit tests for classes that greatly simplifies the process compared to
traditional mocking libraries and dependency injection frameworks.
Consider the following UserService and Database classes:
import{TestBed,Mocked}from'@suites/unit';import{Database,UserService}from'./user.service';describe('User Service Unit Spec',()=>{letuserService: UserService;// π§ͺ Declare the unit under testletdatabase: Mocked<Database>;// π Declare a mocked dependencybeforeAll(async()=>{// π Create an isolated test env for the unit (under test) + auto generated mock objectsconst{ unit, unitRef }=awaitTestBed.solitary(UserService).compile();userService=unit;// π Retrieve a dependency (mock) from the unit referencedatabase=unitRef.get(Database);});// β Test test testtest('should return users from the database',async()=>{constmockUsers: User[]=[{id: 1,name: 'John'},{id: 2,name: 'Jane'}];database.getUsers.mockResolvedValue(mockUsers);constusers=awaituserService.getAllUsers();expect(database.getUsers).toHaveBeenCalled();expect(users).toEqual(mockUsers);});});
With TestBed, an instance of UserService is created with mock objects automatically generated for its dependencies.
During the test, you have direct access to the automatically generated mock object for the Database dependency.
Then, to fully integrate Suites with your dependency injection framework and testing library, install the corresponding
adapters for your project:
$ npm i -D @suites/doubles.jest @suites/di.nestjs
Suites will automatically detect the installed adapters and configure itself accordingly.
Prerequisites
TypeScript project: With decorators and metadata reflection enabled
Node.js environment: Compatible with Node.js 16.x and above
Dependency injection framework: One of the supported frameworks
Testing library: One of the supported libraries
Supported DI Frameworks
DI Framework
Package Name
NestJS
@suites/di.nestjs
Inversify
@suites/di.inversify
TSyringe
Soon!
Supported Mocking Libraries
Testing Library
Package Name
Jest
@suites/doubles.jest
Sinon
@suites/doubles.sinon
Vitest
@suites/doubles.vitest
Bun
Soon!
Deno
Soon!
π Migrating from Automock
If you're currently using Automock, we've created a comprehensive migration guide to help you transition to Suites. The
guide covers all the changes and improvements, making the upgrade process smooth and straightforward.
Your support helps us continue improving Suites and developing new features!
π License
Distributed under the Apache (Apache-2.0) License. See LICENSE for more information.
About
Unit testing framework for dependency injection that automates mocking and simplifies test setup, reducing boilerplate code and enabling developers to build comprehensive and reliable test suites with a standardized, type-safe API