import type { IdentifierToFinal, IdentifierToMockImplWithCb } from '../dependency-container.js'; import type { Type } from '@suites/types.common'; import type { IdentifierMetadata } from '@suites/types.di'; import type { MockOverride, UnitTestBed } from '../../types.js'; export declare abstract class TestBedBuilder implements TestBedBuilder { protected readonly identifiersToBeMocked: IdentifierToMockImplWithCb[]; protected readonly identifiersToBeFinalized: IdentifierToFinal[]; mock(type: Type): MockOverride; mock(type: Type, identifierMetadata: IdentifierMetadata): MockOverride; mock(token: string): MockOverride; mock(token: string, identifierMetadata: IdentifierMetadata): MockOverride; mock(token: symbol): MockOverride; mock(token: symbol, identifierMetadata: IdentifierMetadata): MockOverride; mock(identifier: Type | string | symbol, identifierMetadata?: IdentifierMetadata): MockOverride; /** * Compiles the UnitTestBed instance. * * This method sets up and initializes the test environment for the specified class, * resolving all dependencies and applying the defined mocks. The result is a * `UnitTestBed` instance that provides access to the class under test and its * mocked dependencies, ready for testing. * * @since 3.0.0 * @returns A Promise that resolves to the compiled `UnitTestBed` instance. * @template TClass The type of the class being tested. * @example * ```ts * const unitTestBed = await testBedBuilder.compile(); * const { unit, unitRef } = unitTestBed; * // unit is the instance of the class under test * // unitRef provides access to the mocked dependencies * ``` */ abstract compile(): Promise>; } /** * Interface representing a builder for configuring and creating test beds for unit testing classes. * * @template TClass The type of the class being tested. * @since 3.0.0 */ export interface TestBedBuilder { /** * Declares a dependency to be mocked using its type. * * @since 3.0.0 * @template TDependency The type of the dependency being mocked. * @param type - The type representing the dependency to be mocked. * @template TClass The type of the class being tested. * @returns An instance of MockOverride for further configuration. * @example * ```ts * const mockOverride = testBedBuilder.mock(MyService); * ``` */ mock(type: Type): MockOverride; /** * Declares a dependency to be mocked using its type along with a corresponding metadata object. * * @since 3.0.0 * @template TDependency The type of the dependency being mocked. * @template TClass The type of the class being tested. * @param type - The type representing the dependency to be mocked. * @param identifierMetadata - Metadata object that corresponds to the type identifier. * @returns An instance of MockOverride for further configuration. * @example * ```ts * const mockOverride = testBedBuilder.mock(MyService, metadata); * ``` */ mock(type: Type, identifierMetadata: IdentifierMetadata): MockOverride; /** * Declares a dependency to be mocked using a string-based token. * * @since 3.0.0 * @template TDependency The type of the dependency being mocked. * @template TClass The type of the class being tested. * @param token - The string-based token representing the dependency to be mocked. * @returns An instance of MockOverride for further configuration. * @example * ```ts * const mockOverride = testBedBuilder.mock('MyService'); * ``` */ mock(token: string): MockOverride; /** * Declares a dependency to be mocked using a string-based token along with a corresponding metadata object. * * @since 3.0.0 * @template TDependency The type of the dependency being mocked. * @template TClass The type of the class being tested. * @param token - The string-based token representing the dependency to be mocked. * @param identifierMetadata - Metadata object that corresponds to the string-based token. * @returns An instance of MockOverride for further configuration. * @example * ```ts * const mockOverride = testBedBuilder.mock('MyService', metadata); * ``` */ mock(token: string, identifierMetadata: IdentifierMetadata): MockOverride; /** * Declares a dependency to be mocked using a symbol-based token. * * @since 3.0.0 * @template TDependency The type of the dependency being mocked. * @template TClass The type of the class being tested. * @param token - The symbol-based token representing the dependency to be mocked. * @returns An instance of MockOverride for further configuration. * @example * ```ts * const mockOverride = testBedBuilder.mock(MY_SERVICE_SYMBOL); * ``` */ mock(token: symbol): MockOverride; /** * Declares a dependency to be mocked using a symbol-based token along with a corresponding metadata object. * * @since 3.0.0 * @template TDependency The type of the dependency being mocked. * @template TClass The type of the class being tested. * @param token - The symbol-based token representing the dependency to be mocked. * @param identifierMetadata - Metadata object that corresponds to the symbol-based token. * @returns An instance of MockOverride for further configuration. * @example * ```ts * const mockOverride = testBedBuilder.mock(MY_SERVICE_SYMBOL, metadata); * ``` */ mock(token: symbol, identifierMetadata: IdentifierMetadata): MockOverride; /** * Declares a dependency to be mocked using its type, string-based token, or symbol-based token, * with an optional metadata object. * * @since 3.0.0 * @template TDependency The type of the dependency being mocked. * @template TClass The type of the class being tested. * @param identifier - The type or token representing the dependency to be mocked. * @param identifierMetadata - Optional metadata object for the identifier. * @returns An instance of MockOverride for further configuration. * @example * ```ts * const mockOverride = testBedBuilder.mock(MyService); * // or * const mockOverride = testBedBuilder.mock('MyService'); * // or * const mockOverride = testBedBuilder.mock(MY_SERVICE_SYMBOL, metadata); * ``` */ mock(identifier: Type | string | symbol, identifierMetadata?: IdentifierMetadata): MockOverride; } /** * Interface representing a builder for configuring and creating test beds for unit testing classes. * * @template TClass The type of the class being tested. */ export interface TestBedBuilder { /** * Declares a dependency to be mocked using its type. * * @since 3.0.0 * @template TDependency The type of the dependency being mocked. * @param type - The type representing the dependency to be mocked. * @returns An instance of MockOverride for further configuration. * @example * ```ts * const mockOverride = testBedBuilder.mock(MyService); * ``` */ mock(type: new (...args: any[]) => TDependency): MockOverride; /** * Declares a dependency to be mocked using a string-based token. * * @since 3.0.0 * @template TDependency The type of the dependency being mocked. * @param token - The string-based token representing the dependency to be mocked. * @returns An instance of MockOverride for further configuration. * @example * ```ts * const mockOverride = testBedBuilder.mock('MyService'); * ``` */ mock(token: string): MockOverride; /** * Declares a dependency to be mocked using a symbol-based token. * * @since 3.0.0 * @template TDependency The type of the dependency being mocked. * @param token - The symbol-based token representing the dependency to be mocked. * @returns An instance of MockOverride for further configuration. * @example * ```ts * const mockOverride = testBedBuilder.mock(MY_SERVICE_SYMBOL); * ``` */ mock(token: symbol): MockOverride; /** * Declares a dependency to be mocked using its type, string-based token, or symbol-based token. * * @since 3.0.0 * @template TDependency The type of the dependency being mocked. * @param identifier - The type or token representing the dependency to be mocked. * @param identifierMetadata - Optional metadata object for the identifier. * @returns An instance of MockOverride for further configuration. * @example * ```ts * const mockOverride = testBedBuilder.mock(MyService); * // or * const mockOverride = testBedBuilder.mock('MyService'); * // or * const mockOverride = testBedBuilder.mock(MY_SERVICE_SYMBOL, metadata); * ``` */ mock(identifier: new (...args: any[]) => TDependency | string | symbol, identifierMetadata?: IdentifierMetadata): MockOverride; }