@gluonjs/test-utils / packages/test-utils/src / ComponentMountOptions
Interface: ComponentMountOptions<Props>
Extends
Type Parameters
Props
Props extends object
Properties
attachTo?
readonlyoptionalattachTo?:Element
Inherited from
container?
readonlyoptionalcontainer?:Element
Inherited from
name?
readonlyoptionalname?:string
Inherited from
plugins?
readonlyoptionalplugins?: readonly (GluonAppPlugin<void> |TestPluginUse)[]
Inherited from
props
readonlyprops:Props
providers?
readonlyoptionalproviders?: readonlyTestProvider<unknown>[]
Inherited from
setup?
readonlyoptionalsetup?: (app) =>void
Parameters
app
Returns
void
Inherited from
Example
Configure the initial typed props and fixture identity used when mounting a functional component under test:
import { html } from '@gluonjs/core';
import {
mountComponent,
renderFixture,
type ComponentMountOptions,
type FixtureEventRecord,
} from '@gluonjs/test-utils';
type CounterProps = { count: number; save(value: number): void };
const options = {
name: 'counter',
props: { count: 1, save: (value: number) => console.log(value) },
} satisfies ComponentMountOptions<CounterProps>;
const counter = mountComponent(
({ count, save }: CounterProps) => html`<button @click=${() => save(count)}>${count}</button>`,
options,
);
await counter.setProps({ count: 2 });
counter.get<HTMLButtonElement>('button').click();
const event = { name: 'save', event: new CustomEvent('save', { detail: 2 }) } satisfies FixtureEventRecord;
const staticFixture = renderFixture(() => html`<p>${event.name}</p>`);
console.log(counter.text(), staticFixture.text());
staticFixture.cleanup();
counter.cleanup();