import type { DeclareElements, JsxNode, LitElement, ToElement } from "@arcgis/lumina"; import type { TemplateResult } from "lit"; export interface RenderResult { /** * The custom element proxy that is attached to the DOM. * * This element will contain all the public properties and public methods of * your custom element, but it will not contain any internal members. */ readonly el: ToElement & { shadowRoot: ShadowRoot; }; /** * This is the actual LitElement that you authored in the code. * * It is not directly connected to the DOM (instead, a proxy element is used * to facilitate lazy-loading). * * All public and private members of your custom element are available here. */ readonly component: Component; /** * The container element that was used to render the component. * * This element is useful to inspect for functional components and components * that do not use shadow DOM. */ readonly container: HTMLElement; /** * A callback for triggering component re-render. Optionally, if the first * argument to `mount()` was a function, that function will be called * again to get a new template. * * @example * ```tsx * let someValue = 1; * const { el, component, reRender } = await mount( * ()=> * ); * * someValue = 2; * await reRender(); * ``` * * The above is roughly equivalent to manually setting `el.someProp = 2`. */ reRender(): Promise; } export interface RenderOptions { /** * The parent to attach this component to. * * @default document.body */ readonly parent?: DocumentFragment | HTMLElement; /** * `mount()` will return a promise that resolves after the element * is connected to the DOM, fully loaded and rendered. * * This callback is for executing code right after the element is connected to * the DOM, but before it is fully loaded and rendered. * * @param el */ afterConnect?(el: ToElement & { shadowRoot: ShadowRoot; }): Promise | void; /** * This option only needs to be used if you created the custom element * dynamically (inside the test file), rather than in a separate .tsx file. * Also, if you already passed the dynamic custom element class as the first * argument to `mount()`, you don't need to provide it again here. */ readonly dynamicComponents?: (typeof LitElement)[]; /** * Whether to cleanup the document body after the test. Set this to false if * you wish to reuse the same component between different test() blocks. * * @default true */ readonly cleanupAfterTest?: boolean; } /** * Render Lit Element in a test environment. * * @param tagName * @param options * @see https://webgis.esri.com/references/lumina/testing * @example * ```tsx * // Create component based on a tag name * const { el, component } = await mount("arcgis-counter"); * // Create component based on JSX (explicit type annotation necessary) * const { el, component } = await mount<"arcgis-counter">(); * // You can also use the component class as the explicit type annotation: * const { el, component } = await mount(); * ``` * @example * In it's simplest form, what this function is doing is the following: * * ```tsx * import { render } from "lit"; * render(, document.body); * const el = document.querySelector("arcgis-counter")!; * await el.componentOnReady(); * ``` */ export function mount(tagName: TagName, options?: RenderOptions): Promise>; /** * @param template * @param options */ export function mount(template: TemplateResult | (() => JsxNode), options?: RenderOptions> & { dynamicComponents: [Class]; }): Promise>>; /** * @param jsx * @param options */ export function mount(jsx: TemplateResult | (() => JsxNode), options?: RenderOptions<[TagName] extends [never] ? LitElement : DeclareElements[TagName]>): Promise>; /** * @param template * @param options */ export function mount(template: Class | TemplateResult | (() => JsxNode), options?: RenderOptions>): Promise>>; /** * @param template * @param options */ export function mount(template: TemplateResult | (() => JsxNode) | (new () => Component), options?: RenderOptions): Promise>; /** * Find the first direct child Lumina component element. If failed to find a * direct child, do a priority-first search in the children of the children. * * @param container * @experimental */ export function findFirstComponent(container: ParentNode): Element | undefined;