import { type Mock } from 'vitest';
/**
* Base configuration for what to spy on in a component
*/
interface SpyConfigBase {
/**
* Method names to spy on (calls original implementation)
*/
methods?: string[];
/**
* Pre-configured mocks to replace methods. The mock is applied before lifecycle runs,
* allowing you to control return values for methods called during initialization.
* @example
* ```ts
* const loadUserMock = vi.fn().mockResolvedValue({ id: 1, name: 'Test' });
* const { root } = await render(, {
* spyOn: { mocks: { loadUser: loadUserMock } }
* });
* expect(loadUserMock).toHaveBeenCalled();
* ```
*/
mocks?: Record;
/**
* Property names to spy on
*/
props?: string[];
/**
* Lifecycle method names to spy on ('componentWillLoad', 'componentDidRender')
*/
lifecycle?: string[];
}
/**
* Configuration for what to spy on in a component.
* Can include per-component overrides via the `components` property.
*/
export interface SpyConfig extends SpyConfigBase {
/**
* Per-component spy configurations, keyed by tag name.
* These override the base config for specific components.
* @example
* ```ts
* spyOn: {
* lifecycle: ['componentDidLoad'], // applies to all
* components: {
* 'my-select': { methods: ['open', 'close'] },
* 'my-option': { methods: ['select'] },
* }
* }
* ```
*/
components?: Record;
}
/**
* A mock with access to the original implementation
*/
interface MockWithOriginal extends Mock {
/**
* The original method implementation, bound to the component instance.
* Call this within mockImplementation to augment rather than replace.
*/
original?: (...args: any[]) => any;
}
/**
* Container for all spies on a component instance
*/
export interface ComponentSpies {
/**
* Spies on component methods (calls through to original)
*/
methods: Record;
/**
* Mocks on component methods (pure stubs, doesn't call original).
* Each mock has an `original` property to access the original implementation.
*/
mocks: Record;
/**
* Spies on property setters
*/
props: Record;
/**
* Spies on lifecycle methods
*/
lifecycle: Record;
/**
* The target instance (either $lazyInstance$ or the element itself for custom-elements output)
*/
instance: any;
/**
* Reset all spies/mocks - clears call history AND resets implementations to default.
*/
resetAll: () => void;
}
/**
* Set spy config for the next render call. Used internally by render().
* @internal
*/
export declare function setRenderSpyConfig(config: SpyConfig | null): void;
/**
* Get the spies for a rendered component instance.
* Spies are lazily applied on first call to ensure the instance is fully constructed.
*
* @param element - The rendered component element
* @returns The spies object or undefined if no spies were registered
*/
export declare function getComponentSpies(element: HTMLElement): ComponentSpies | undefined;
/**
* Clear spy registrations. Call this in afterEach to reset state between tests.
*
* @param tagName - Optional tag name to clear. If omitted, clears all registrations.
*
* @example
* ```ts
* afterEach(() => {
* clearComponentSpies(); // Clear all
* });
*
* // Or clear specific component
* clearComponentSpies('my-button');
* ```
*/
export declare function clearComponentSpies(tagName?: string): void;
export {};
//# sourceMappingURL=spy-helper.d.ts.map