import { JasmineSpy, JasmineMethodSpy } from './jasmine-compat.js'; export { JasmineAccessorSpies, JasmineAccessorSpy, JasmineAnd, JasmineCallInfo, JasmineCalls, JasmineNamespaces, JasmineStrategies, JasmineWithArgsAnd, JasmineWithArgsSync, enableJasmineCompat } from './jasmine-compat.js'; import { C as ClassType, m as ClassSpyConfiguration, q as OnlyMethodKeysOf, F as Func } from './types-BM3BcWj1.js'; export { r as OnlyObservablePropsOf, s as OnlyPropsOf } from './types-BM3BcWj1.js'; import { expect } from 'vitest'; /** * `ClassSpyConfiguration` plus the key `jasmine-auto-spies` deprecated but still accepts. * * Carried here and not in the core configuration: it means exactly what `methodsToSpyOn` means, it * has warned on use upstream since v6, and adding a deprecated alias to the type every consumer * sees would advertise it to people who have never heard of it. */ interface JasmineClassSpyConfiguration extends ClassSpyConfiguration { /** * @deprecated The pre-6.x name for {@link ClassSpyConfiguration.methodsToSpyOn}, accepted so a * migrated configuration object still compiles and still works. It is merged into * `methodsToSpyOn`, exactly as upstream merges it. Rename it and the warning goes away. */ providedMethodNames?: OnlyMethodKeysOf[]; } /** * `createSpyFromClass`, returning a spy typed with `.and` / `.calls` / `.withArgs`. * * Same two argument forms as upstream — a bare list of method names, or a configuration object — * and the same runtime behind them as the core factory, so everything the core offers * (`onlyMethodsToSpyOn`, `strict`, `returns`, `fillMissing`, matcher-aware `calledWith`) is * available to a migrating suite the day it lands. */ declare function createSpyFromClass(ObjectClass: ClassType, methodsToSpyOnOrConfig?: JasmineClassSpyConfiguration | OnlyMethodKeysOf[]): JasmineSpy; /** * `createFunctionSpy('fn')`, returning a spy typed with the jasmine namespaces. * * The generic is not inferable from a string, so it is given explicitly — exactly as upstream. */ declare function createFunctionSpy(name: string): JasmineMethodSpy; /** What `provideAutoSpy` hands to a DI container. */ type AngularValueProvider = { provide: ClassType; useValue: JasmineSpy; }; /** * `{ provide: Class, useValue: createSpyFromClass(Class, …) }`, spelled once. * * A structural literal with no framework import, so it is accepted by Angular's `TestBed`, NestJS's * `Test.createTestingModule` and anything else that reads `{ provide, useValue }` — which is how * upstream's helper works too. * * Getting the double back out is where the two libraries differ. Upstream needs * `TestBed.inject(Class)`, losing the type on the way out; `injectSpy(Class)` from * `vitest-auto-spy/angular` returns it typed. */ declare function provideAutoSpy(ObjectClass: ClassType, methodsToSpyOnOrConfig?: JasmineClassSpyConfiguration | OnlyMethodKeysOf[]): AngularValueProvider; /** The object `createSpyObj` builds: one jasmine-flavoured spy per name, plus any seeded properties. */ type SpyObj = { [K in Props]: unknown; } & { [K in Names]: JasmineMethodSpy; }; /** Either upstream form of a name list: bare names, or names mapped to the value each should carry. */ type NameList = Names[] | Record; /** * `jasmine.createSpyObj` — the global a jasmine suite reaches for when there is no class to read. * * All of upstream's forms work: a list of method names or a map of name to return value, with or * without a leading `baseName`, and an optional third argument of properties in either of the same * two shapes. * * ```ts * const store = createSpyObj('store', ['load', 'save']); * const clock = createSpyObj('clock', { now: 1700000000 }); * const user = createSpyObj('user', ['save'], { id: 7 }); * ``` * * The `baseName` is optional exactly as in jasmine, where it names the spies in failure output; the * spies here are named `baseName.method` for the same reason. Prefer `createSpyFromClass` where a * class exists and `createAutoMock()` where only an interface does — both of those check the * names against the type, and this one cannot. */ declare function createSpyObj(baseName: string, methodNames: NameList, propertyNames?: NameList): SpyObj; declare function createSpyObj(methodNames: NameList, propertyNames?: NameList): SpyObj; declare global { namespace Chai { interface Assertion { /** See {@link AsymmetricMatchersContaining.jasmineTruthy}. */ jasmineTruthy(): void; /** See {@link AsymmetricMatchersContaining.jasmineFalsy}. */ jasmineFalsy(): void; /** See {@link AsymmetricMatchersContaining.jasmineEmpty}. */ jasmineEmpty(): void; /** See {@link AsymmetricMatchersContaining.jasmineNotEmpty}. */ jasmineNotEmpty(): void; /** See {@link AsymmetricMatchersContaining.jasmineIs}. */ jasmineIs(sample: unknown): void; /** See {@link AsymmetricMatchersContaining.jasmineMapContaining}. */ jasmineMapContaining(sample: Map): void; /** See {@link AsymmetricMatchersContaining.jasmineSetContaining}. */ jasmineSetContaining(sample: Set): void; /** See {@link AsymmetricMatchersContaining.jasmineArrayWithExactContents}. */ jasmineArrayWithExactContents(sample: unknown[]): void; } } } declare module 'vitest' { interface AsymmetricMatchersContaining { /** jasmine's `jasmine.truthy()` — any value that is loosely true. */ jasmineTruthy(): unknown; /** jasmine's `jasmine.falsy()` — any value that is loosely false. */ jasmineFalsy(): unknown; /** jasmine's `jasmine.empty()` — `''`, `[]`, `{}`, an empty `Map` or an empty `Set`. */ jasmineEmpty(): unknown; /** jasmine's `jasmine.notEmpty()` — anything {@link AsymmetricMatchersContaining.jasmineEmpty} rejects. */ jasmineNotEmpty(): unknown; /** jasmine's `jasmine.is(sample)` — reference identity, where every other matcher deep-compares. */ jasmineIs(sample: unknown): unknown; /** jasmine's `jasmine.mapContaining(sample)` — a `Map` holding at least these entries. */ jasmineMapContaining(sample: Map): unknown; /** jasmine's `jasmine.setContaining(sample)` — a `Set` holding at least these members. */ jasmineSetContaining(sample: Set): unknown; /** jasmine's `jasmine.arrayWithExactContents(sample)` — the same members, in any order. */ jasmineArrayWithExactContents(sample: unknown[]): unknown; } } /** * Register jasmine's eight orphan asymmetric matchers with the runner. * * Called for you the first time anything on the `jasmine` namespace is used, so a migrating suite * needs no setup step; exported because `expect.jasmineEmpty()` and friends are usable directly, and * a suite that only wants those should be able to ask for them. Idempotent. */ declare function registerJasmineMatchers(): void; /** * The `jasmine` global, as an import. * * A jasmine suite reaches for `jasmine.objectContaining(…)`, `jasmine.any(String)`, * `jasmine.createSpyObj(…)` and `jasmine.clock().tick(…)` in files that have nothing to do with * auto-spies, and under Vitest every one of them is a `ReferenceError`. Rewriting them is the right * end state and the codemod does it — but a suite of two thousand specs has to *run* before anyone * can tell whether the rewrite was correct. * * So: one import restores the whole namespace. * * ```ts * import { jasmine } from 'vitest-auto-spy/jasmine'; * ``` * * Nothing here is a reimplementation. Each member forwards to the Vitest primitive that means the * same thing, and the members with no Vitest twin forward to this package's own * ({@link jasmine-matchers}, {@link jasmine-factories}). What it deliberately does *not* do is * install itself on `globalThis`: a global that appears because something imported a library is * exactly the kind of action-at-a-distance that makes a migration hard to reason about, and an * explicit import is one line per file that the codemod later deletes. */ /** jasmine's `clock()` handle, over Vitest's fake timers. */ interface JasmineClock { install(): JasmineClock; uninstall(): void; /** * Advance the fake clock synchronously, as jasmine does. * * A promise that a timer resolves is *not* settled by this — jasmine has the same limitation. * `advanceTimers(ms)` from the core entry awaits the microtask queue as well, and is what a spec * that awaits something after ticking actually wants. */ tick(ms: number): void; mockDate(date?: Date): void; withMock(body: () => void): void; } /** * A spy under jasmine's own factory name. * * jasmine's second argument is the function `.and.callThrough()` should call. An auto-spy has no * original, so `callThrough` normally restores this library's dispatch; when an original is given * here, it restores that instead — which is what the two-argument form means. */ declare function createSpy(name?: string, originalFn?: Func): ReturnType>; /** * The `jasmine` namespace, as an importable object. * * Every member either forwards to its Vitest twin or, where there is none, to this package's own * implementation. Four of jasmine's members are deliberately absent, because forwarding them would * be a lie: `getEnv()` (Vitest's ordering and bail are config, not a runtime environment), * `addCustomObjectFormatter` (snapshot serializers are a different mechanism with different rules), * `addSpy`/`pp` (jasmine internals), and `Spy` / `SpyObj` as *values* — those are types, and they * are exported as types from `vitest-auto-spy/jasmine`. */ declare const jasmine: { any: (constructor: unknown) => unknown; anything: () => unknown; objectContaining: (sample: Record) => unknown; arrayContaining: (sample: unknown[]) => unknown; stringMatching: (sample: RegExp | string) => unknown; stringContaining: (sample: string) => unknown; truthy: () => unknown; falsy: () => unknown; empty: () => unknown; notEmpty: () => unknown; is: (sample: unknown) => unknown; mapContaining: (sample: Map) => unknown; setContaining: (sample: Set) => unknown; arrayWithExactContents: (sample: unknown[]) => unknown; createSpy: typeof createSpy; createSpyObj: typeof createSpyObj; clock: () => JasmineClock; addMatchers: (matchers: Parameters[0]) => void; addCustomEqualityTester: (tester: Parameters[0][number]) => void; DEFAULT_TIMEOUT_INTERVAL: number; }; export { type AngularValueProvider, ClassSpyConfiguration, ClassType, type JasmineClassSpyConfiguration, type JasmineClock, JasmineMethodSpy, JasmineSpy, OnlyMethodKeysOf, JasmineSpy as Spy, type SpyObj, createFunctionSpy, createSpyFromClass, createSpyObj, jasmine, provideAutoSpy, registerJasmineMatchers };