import { Mock } from 'vitest'; import { F as Func, h as AddSpyMethodsByReturnTypes, g as AddPromiseSpyMethods, O as ObservableLike, f as AddObservableSpyMethods, w as SpyDisposable } from './types-BM3BcWj1.js'; /** * Install the `.and`, `.calls` and `.withArgs` namespaces on every spy built afterwards. * * Idempotent, and order matters only in one direction: spies built *before* the call do not get the * namespaces, so this belongs in a setup file rather than inside a `beforeEach` that runs after the * double is created. The `vitest-auto-spy/jasmine` entry calls it on import, which is the usual way * in. */ declare function enableJasmineCompat(): void; /** * One recorded call, in jasmine's shape. * * `object` and `returnValue` are best-effort: the adapter normalises recorded calls down to their * argument tuples, which is all the core ever needs, so these two are read off the host mock's own * bookkeeping when it keeps any. Vitest and Bun both do; `node:test` records the result on the call * entry instead, and that shape is read too. Where a runner keeps neither, the field is `undefined` * rather than absent — a spec that asserts on it sees a missing value, not a missing property. */ interface JasmineCallInfo { object: unknown; args: unknown[]; returnValue: unknown; } /** * The typed shape of the `.and` / `.calls` / `.withArgs` namespaces, and the `Spy` a suite * arriving from `jasmine-auto-spies` imports instead of the core one. * * These types are **not** folded into the core `Spy`, deliberately. `.and` is a migration * surface, not a second way to write new specs, and putting ten jasmine strategy names into the * completion list of every spy in every project would tax the ninety-odd percent of users who never * touched jasmine. A suite that wants them says so once, in its import. * * The runtime half lives in `jasmine-namespaces.ts` and is installed only by the * `vitest-auto-spy/jasmine` entry. */ /** * jasmine's spy **strategies** — the `.and` members that replace what the spy does. * * Each returns the spy, as jasmine's do. Worth knowing, and true of jasmine as well: every one of * these installs an implementation, so a `calledWith` chain configured beforehand stops deciding * the value. {@link JasmineStrategies.callThrough} puts the library's own dispatch back. */ interface JasmineStrategies { /** The spy's name — jasmine's `spy.and.identity`. */ readonly identity: string; /** `spy.mockReturnValue(value)` under jasmine's name. */ returnValue(value: ReturnType): AddSpyMethodsByReturnTypes; /** One value per call, in order; `undefined` once the list runs out. */ returnValues(...values: ReturnType[]): AddSpyMethodsByReturnTypes; /** `spy.mockImplementation(fake)` under jasmine's name. */ callFake(fake: Method): AddSpyMethodsByReturnTypes; /** * Put the library's own dispatch back, undoing a `returnValue` / `callFake` / `stub` — so * `calledWith`, `resolveWith` and `nextWith` decide the value again. * * @remarks * This is **not** jasmine's `callThrough`. There, it calls the real method a `spyOn` replaced; an * auto-spy never wrapped a real method, so there is nothing to call through *to* — which is why * `callThrough()` on a `jasmine-auto-spies` spy silently produced `undefined`. Restoring the * dispatch is the useful reading of the same word. */ callThrough(): AddSpyMethodsByReturnTypes; /** Answer `undefined` and nothing else. */ stub(): AddSpyMethodsByReturnTypes; /** Throw a message, an `Error`, or an error class constructed with `message`. */ throwError(message: string): AddSpyMethodsByReturnTypes; throwError(error: Error): AddSpyMethodsByReturnTypes; throwError(errorClass: new (message?: string) => Error, message?: string): AddSpyMethodsByReturnTypes; /** * Return a promise resolved with `value`. * * The blunt form: it replaces the implementation, so `calledWith` no longer applies. Prefer * `.and.resolveWith(value)` on a promise-returning method, which routes through the same * machinery `calledWith` uses. */ resolveTo(value?: Awaited>): AddSpyMethodsByReturnTypes; } /** * The helper bundle a method's return type earns: the promise helpers for a `Promise`, the * observable ones for a stream, and `Fallback` for everything else. * * One conditional for both `.and` namespaces — `spy.and` falls back to nothing, and * `spy.withArgs(…).and` falls back to its own terminal. */ type HelpersForReturn = Method extends (...args: any[]) => infer Returned ? [Returned] extends [Promise] ? AddPromiseSpyMethods

: [Returned] extends [ObservableLike] ? AddObservableSpyMethods : Fallback : Fallback; /** `.and` on a method spy: jasmine's strategies plus whichever helper bundle the return type earns. */ type JasmineAnd = HelpersForReturn & JasmineStrategies; /** * jasmine's `.calls` bookkeeping. * * `object` and `returnValue` on a {@link JasmineCallInfo} are read from the host runner's own * records and are `undefined` on a runner that keeps none — see `jasmine-namespaces.ts`. */ interface JasmineCalls { any(): boolean; count(): number; argsFor(index: number): unknown[]; allArgs(): unknown[][]; all(): JasmineCallInfo[]; first(): JasmineCallInfo | undefined; mostRecent(): JasmineCallInfo | undefined; thisFor(index: number): unknown; /** Clear the recorded calls — the spy's configuration is untouched. */ reset(): void; /** * A no-op, kept callable so a migrated spec still runs. * * jasmine copies call arguments defensively; no Vitest-family runner does, and snapshotting every * argument of every call would slow every spy in the suite for a helper that appears in a handful * of specs. Where the code under test mutates an argument afterwards, take the copy yourself. */ saveArgumentsByValue(): void; } /** * The strategies `spy.withArgs(…).and` carries whatever the method returns. * * jasmine's `withArgs` chain offers every strategy `spy.and` does. Three of them — `callFake`, * `callThrough` and `returnValues` — install an *implementation*, which answers every call whatever * its arguments, so they have no argument-scoped form here: they are declared, and they throw with * the alternative named rather than being absent from the type and failing as `… is not a function`. */ interface JasmineWithArgsStrategies { /** Answer `undefined` for these arguments. */ stub(): void; /** Throw a message, an `Error`, or an error class constructed with `message`, for these arguments. */ throwError(message: string): void; throwError(error: Error): void; throwError(errorClass: new (message?: string) => Error, message?: string): void; /** Answer a promise resolved with `value` for these arguments. */ resolveTo(value?: Awaited>): void; /** @deprecated Not supported per argument list — it throws. Use `spy.and.callFake(…)` for the whole spy. */ callFake(fake: Method): never; /** @deprecated Not supported per argument list — it throws. Use `spy.and.callThrough()` for the whole spy. */ callThrough(): never; /** @deprecated Not supported per argument list — it throws. Use `spy.and.returnValues(…)` for the whole spy. */ returnValues(...values: ReturnType[]): never; } /** What `spy.withArgs(…).and` offers for a sync method: jasmine's terminal, plus this library's name for it. */ interface JasmineWithArgsSync { returnValue(value: ReturnType): void; mockReturnValue(value: ReturnType): void; } /** `spy.withArgs(…).and` — the same object `calledWith(…)` returns, under jasmine's namespace. */ type JasmineWithArgsAnd = HelpersForReturn> & JasmineWithArgsStrategies; /** The three namespaces the jasmine layer adds to a method spy. */ interface JasmineNamespaces { and: JasmineAnd; calls: JasmineCalls; /** * jasmine's argument-scoped configuration — this library's `calledWith` with the namespace moved. * * The one thing that does not carry over is jasmine's return value: there, `withArgs` hands back * a *spy*, so `expect(spy.withArgs(1)).toHaveBeenCalled()` is legal and has no counterpart here. * Assert on the spy itself with `toHaveBeenCalledWith(1)`. */ withArgs(...args: Parameters): { and: JasmineWithArgsAnd; }; } /** A method spy with the jasmine namespaces on it. */ type JasmineMethodSpy = AddSpyMethodsByReturnTypes & JasmineNamespaces; /** An accessor spy with the jasmine namespaces on it — no `withArgs`, since there is no dispatch behind it. */ type JasmineAccessorSpy = Mock & { and: JasmineStrategies; calls: JasmineCalls; }; /** The `accessorSpies` bag, typed for jasmine. */ interface JasmineAccessorSpies { accessorSpies: { getters: { [K in keyof T]: JasmineAccessorSpy; }; setters: { [K in keyof T]: JasmineAccessorSpy; }; }; } /** * `Spy` for a suite migrating off `jasmine-auto-spies` — the core `Spy` plus `.and`, `.calls` * and `.withArgs` on every method. * * Two differences from the type of the same name in `jasmine-auto-spies`, both of them removals: * this one carries Vitest's `MockInstance` rather than `jasmine.Spy`, and it therefore does **not** * drag the global `jasmine` namespace into your typecheck. `jasmine-auto-spies` opens its type * entry with `/// `, so importing its `Spy` requires * `@types/jasmine` to be installed even in a project that has no other use for it. */ type JasmineSpy = JasmineAccessorSpies & SpyDisposable & { [K in keyof T]: T[K] extends Func ? JasmineMethodSpy : T[K] extends ObservableLike ? AddObservableSpyMethods & T[K] : T[K]; }; export { type JasmineAccessorSpies, type JasmineAccessorSpy, type JasmineAnd, type JasmineCallInfo, type JasmineCalls, type JasmineMethodSpy, type JasmineNamespaces, type JasmineSpy, type JasmineStrategies, type JasmineWithArgsAnd, type JasmineWithArgsSync, enableJasmineCompat };