import { C as ClassType, S as Spy, m as ClassSpyConfiguration, q as OnlyMethodKeysOf } from './types-BM3BcWj1.js'; export { I as InjectionLog, T as TrackInjectionsOptions, a as TrackedProvider, t as trackInjections } from './track-injections-Dig5t28T.js'; import 'vitest'; /** `{ provide, useValue }` shape consumed by NestJS's `providers`. */ type NestValueProvider = { provide: ClassType; useValue: Spy; }; /** * The slice of NestJS's `TestingModule` / `ModuleRef` the helper needs: a single * `get(token)` lookup. Typed structurally so this entry never imports * `@nestjs/testing`. */ interface NestModuleRef { get(token: unknown): unknown; } /** * Shorthand NestJS provider: `{ provide, useValue: createSpyFromClass(...) }`. * * @example * ```ts * const moduleRef = await Test.createTestingModule({ * providers: [AuthService, provideAutoSpy(UserService)], * }).compile(); * ``` */ declare function provideAutoSpy(ObjectClass: ClassType, methodsToSpyOnOrConfig?: ClassSpyConfiguration | OnlyMethodKeysOf[]): NestValueProvider; /** * Resolve a provider from a NestJS `TestingModule`, already typed as `Spy`. * * @example * ```ts * const users = injectSpy(moduleRef, UserService); // the module reference comes FIRST * * users.findByEmail.resolveWith({ id: 1 }); * ``` * * @remarks * The module reference is the first argument. Nest has no ambient injector, so the one-argument * `injectSpy(token)` of `vitest-auto-spy/angular` — which reads the global `TestBed` — has no * counterpart here and the `moduleRef` from `Test.createTestingModule(…).compile()` has to be * passed in. It has no counterpart of that helper's "not an auto-spy" warning either: a provider * listed as the bare class instead of `provideAutoSpy(X)` is built for real, comes back typed * `Spy` all the same, and the failure arrives a line later when `.mockReturnValue(…)` is called * on the real method. */ declare function injectSpy(moduleRef: NestModuleRef, token: ClassType | (abstract new (...args: never[]) => T)): Spy; /** A class `new` accepts. An abstract class is not one, which is what keeps it out of `expose`. */ type NestUnitClass = new (...args: never[]) => T; /** * A provider that wins over the auto-spies and over `expose`. The three shapes Nest accepts without * an `inject` list; `provideAutoSpy(X)` output is the `useValue` one. */ type NestUnitProvider = { provide: unknown; useClass: NestUnitClass; } | { provide: unknown; useFactory: () => unknown; } | { provide: unknown; useValue: unknown; }; /** Options for {@link createNestUnit}. */ interface CreateNestUnitOptions { /** * Collaborators constructed for real, their own dependencies auto-spied — Suites' `sociable() * .expose()`. Sugar for `{ provide: X, useClass: X }`, minus the right to read it back as a spy. */ expose?: readonly NestUnitClass[]; /** * Wins over the auto-spies and over `expose`: `provideAutoSpy(X, config)` output, `{ provide: * 'CONFIG', useValue }`, `{ provide: Abstract, useClass: Impl }`, `{ provide, useFactory }` (zero * arguments, called once). */ providers?: readonly NestUnitProvider[]; } /** Resolve a dependency exactly as the unit sees it: the provided value if given, the auto-spy otherwise. */ interface NestUnitSpies { get(token: ClassType | (abstract new (...args: never[]) => D)): Spy; get(token: unknown): Spy; /** Tokens the graph asked for and nothing provided or exposed — the ones answered with a double. */ autoSpiedTokens(): unknown[]; /** The `expose` classes the graph actually built. */ exposedTokens(): unknown[]; } /** What {@link createNestUnit} hands back. */ interface NestUnit { unit: T; spies: NestUnitSpies; } /** * Build `Target` from its metadata with every unprovided dependency spied. * * ```ts * const { unit, spies } = createNestUnit(CartService, { expose: [PricingService] }); * * spies.get(TaxService).rate.mockReturnValue(0.2); * expect(unit.checkout(3)).toBe(36); * ``` */ declare function createNestUnit(Target: NestUnitClass, options?: CreateNestUnitOptions): NestUnit; export { type CreateNestUnitOptions, type NestModuleRef, type NestUnit, type NestUnitClass, type NestUnitProvider, type NestUnitSpies, type NestValueProvider, createNestUnit, injectSpy, provideAutoSpy };