UNPKG

@nuxt/test-utils

Version:
58 lines 2.36 kB
import { n as WrapperSuspendedOptions, t as SetupState } from "../suspended-CVm8y2I3.mjs"; import { config, mount } from "@vue/test-utils"; import { Locator, LocatorSelectors, PrettyDOMOptions } from "vitest/browser"; //#region src/browser/pure.d.ts type ComponentProps<T> = T extends (new (...args: never[]) => { $props: infer P; }) ? NonNullable<P> : T extends ((props: infer P, ...args: never[]) => unknown) ? P : object; type WrapperFn<C> = typeof mount<C>; type WrapperOptions<C> = Omit<WrapperSuspendedOptions<WrapperFn<C>>, 'attachTo'> & { /** Use this option instead of the `@vue/test-utils` `attachTo` option. */ container?: HTMLElement; baseElement?: HTMLElement; }; export interface RenderResult<Props> extends LocatorSelectors { container: HTMLElement; baseElement: HTMLElement; locator: Locator; /** * The return value of the component setup, mocked when the `spy` option is enabled. */ setupState: SetupState; debug(el?: HTMLElement | HTMLElement[] | Locator | Locator[], maxLength?: number, options?: PrettyDOMOptions): void; /** Unmount the component. Also records a `nuxt.unmount` trace mark. */ unmount(): Promise<void>; emitted<T = unknown>(): Record<string, T[]>; emitted<T = unknown[]>(eventName: string): undefined | T[]; /** Re-render the component with new props. Also records a `nuxt.rerender` trace mark. */ rerender(props: Partial<Props>): Promise<void>; } /** * `render` allows you to mount any vue component within the vitest browser mode. * * ```ts * import { page } from 'vitest/browser' * import { render } from '@nuxt/test-utils/browser' * * it('can render', async () => { * const screen = await render(App, { route: '/' }) * * const title = screen.getByRole('heading') * await expect.element(title).toHaveTextContent('Index') * }) * * it('can render with page', async () => { * const screen = await page.render(App, { route: '/' }) * * const title = screen.getByRole('heading') * await expect.element(title).toHaveTextContent('Index') * }) * ``` * * @param component the component to be tested * @param options optional options to set up your component */ export declare function render<T>(component: T, options?: WrapperOptions<T>): Promise<RenderResult<ComponentProps<T>>>; export declare function cleanup(): void; //#endregion export { config };