import type { StubbedInstance } from '@suites/types.doubles'; import type { IdentifierMetadata, InjectableIdentifier } from '@suites/types.di'; import type { Type } from '@suites/types.common'; import type { DependencyContainer, IdentifierToFinal } from './dependency-container.js'; /** * Provides access to mocked dependencies within a test environment. * * The `UnitReference` interface allows retrieving mocked instances of dependencies * after `TestBed.compile()` has been called. This is essential for configuring * mock behaviors and verifying interactions during tests. * * @since 3.0.0 * @see {@link https://suites.dev/docs/api-reference/unit-reference | UnitReference API Reference} * * @example * ```ts * const { unit, unitRef } = await TestBed.solitary(UserService).compile(); * * // Retrieve mocked dependencies by class type * const userRepo = unitRef.get(UserRepository); * userRepo.findById.mockResolvedValue(testUser); * * // Retrieve by string token * const config = unitRef.get('APP_CONFIG'); * * // Retrieve by symbol token * const logger = unitRef.get(LOGGER_TOKEN); * ``` */ export interface UnitReference { /** * Retrieves a mocked dependency by its class type. * * @template TDependency The type of the dependency being retrieved. * @param type - The class constructor representing the dependency. * @returns The mocked instance of the dependency. * @throws {@link DependencyResolutionError} If the dependency is not found or is exposed/final. */ get(type: Type): StubbedInstance; /** * Retrieves a mocked dependency by its class type with additional metadata. * * @template TDependency The type of the dependency being retrieved. * @param type - The class constructor representing the dependency. * @param identifierMetadata - Additional metadata for identifying the dependency. * @returns The mocked instance of the dependency. * @throws {@link DependencyResolutionError} If the dependency is not found or is exposed/final. */ get(type: Type, identifierMetadata: IdentifierMetadata): StubbedInstance; /** * Retrieves a mocked dependency by a string-based token. * * @template TDependency The type of the dependency being retrieved. * @param token - The string token representing the dependency. * @returns The mocked instance of the dependency. * @throws {@link DependencyResolutionError} If the dependency is not found or is exposed/final. */ get(token: string): StubbedInstance; /** * Retrieves a mocked dependency by a string-based token with additional metadata. * * @template TDependency The type of the dependency being retrieved. * @param token - The string token representing the dependency. * @param identifierMetadata - Additional metadata for identifying the dependency. * @returns The mocked instance of the dependency. * @throws {@link DependencyResolutionError} If the dependency is not found or is exposed/final. */ get(token: string, identifierMetadata: IdentifierMetadata): StubbedInstance; /** * Retrieves a mocked dependency by a symbol-based token. * * @template TDependency The type of the dependency being retrieved. * @param token - The symbol token representing the dependency. * @returns The mocked instance of the dependency. * @throws {@link DependencyResolutionError} If the dependency is not found or is exposed/final. */ get(token: symbol): StubbedInstance; /** * Retrieves a mocked dependency by a symbol-based token with additional metadata. * * @template TDependency The type of the dependency being retrieved. * @param token - The symbol token representing the dependency. * @param identifierMetadata - Additional metadata for identifying the dependency. * @returns The mocked instance of the dependency. * @throws {@link DependencyResolutionError} If the dependency is not found or is exposed/final. */ get(token: symbol, identifierMetadata: IdentifierMetadata): StubbedInstance; /** * Retrieves a mocked dependency using a flexible identifier. * * @template TDependency The type of the dependency being retrieved. * @param identifier - The class type, string, or symbol representing the dependency. * @param identifierMetadata - Optional metadata for identifying the dependency. * @returns The mocked instance of the dependency. * @throws {@link DependencyResolutionError} If the dependency is not found or is exposed/final. */ get(identifier: Type | string | symbol, identifierMetadata?: IdentifierMetadata): StubbedInstance; /** * Retrieves a mocked dependency using an injectable identifier. * * @template TDependency The type of the dependency being retrieved. * @param identifier - The injectable identifier representing the dependency. * @param identifierMetadata - Optional metadata for identifying the dependency. * @returns The mocked instance of the dependency. * @throws {@link DependencyResolutionError} If the dependency is not found or is exposed/final. */ get(identifier: InjectableIdentifier, identifierMetadata?: IdentifierMetadata): StubbedInstance; } /** * Implementation of the UnitReference interface that provides access to mocked dependencies. * * @since 3.0.0 * @see {@link https://suites.dev/docs/api-reference/unit-reference | UnitReference API Reference} */ export declare class UnitReference { private readonly mocksContainer; private readonly exposedInstances; private readonly fakedDependencies; constructor(mocksContainer: DependencyContainer, exposedInstances: InjectableIdentifier[], fakedDependencies: IdentifierToFinal[]); get(type: Type): StubbedInstance; get(type: Type, identifierMetadata: IdentifierMetadata): StubbedInstance; get(token: string): StubbedInstance; get(token: string, identifierMetadata: IdentifierMetadata): StubbedInstance; get(token: symbol): StubbedInstance; get(token: symbol, identifierMetadata: IdentifierMetadata): StubbedInstance; get(identifier: Type | string | symbol, identifierMetadata?: IdentifierMetadata): StubbedInstance; }