@gluonjs/test-utils / packages/test-utils/src / ElementFixture
Interface: ElementFixture<ElementType>
Extends
Type Parameters
ElementType
ElementType extends HTMLElement
Properties
active
readonlyactive:boolean
Inherited from
app
readonlyapp:GluonApp
Inherited from
container
readonlycontainer:Element
Inherited from
element
readonlyelement:ElementType
id
readonlyid:number
Inherited from
name
readonlyname:string
Inherited from
Methods
cleanup()
cleanup():
void
Returns
void
Inherited from
emitted()
emitted(
name?): readonlyFixtureEventRecord[]
Parameters
name?
string
Returns
readonly FixtureEventRecord[]
get()
get<
ElementType>(selector):ElementType
Type Parameters
ElementType
ElementType extends Element = Element
Parameters
selector
string
Returns
ElementType
Inherited from
own()
own(
cleanup,label?):void
Parameters
cleanup
() => void | PromiseLike<void>
label?
string
Returns
void
Inherited from
query()
query<
ElementType>(selector):ElementType|null
Type Parameters
ElementType
ElementType extends Element = Element
Parameters
selector
string
Returns
ElementType | null
Inherited from
text()
text():
string
Returns
string
Inherited from
Example
Access the mounted Custom Element and inspect its captured emitted-event history alongside ordinary fixture helpers:
import { createInjectionKey, html } from '@gluonjs/core';
import {
activeFixtureNames,
assertNoFixtureLeaks,
cleanupFixtures,
flushUpdates,
installAutoCleanup,
mountComponent,
mountElement,
settle,
testProvider,
type AutoCleanupOptions,
type BaseMountOptions,
type ComponentFixture,
type ElementFixture,
type ElementMountOptions,
type SettleOptions,
type TestFixture,
type TestProvider,
} from '@gluonjs/test-utils';
const currencyKey = createInjectionKey<string>('currency');
const currency: TestProvider<string> = testProvider(currencyKey, 'EUR');
const base = { name: 'product-price', providers: [currency] } satisfies BaseMountOptions;
const component: ComponentFixture<{ price: number }> = mountComponent(
({ price }) => html`<output>${price.toFixed(2)}</output>`,
{ ...base, props: { price: 129 } },
);
await component.setProps({ price: 119 });
interface ProductPickerElement extends HTMLElement { value: string; }
const elementOptions = {
name: 'product-picker',
attributes: { 'aria-label': 'Product' },
properties: { value: 'lamp' },
slots: { default: 'Choose a product' },
} satisfies ElementMountOptions<ProductPickerElement>;
const element: ElementFixture<ProductPickerElement> = mountElement<ProductPickerElement>('product-picker', elementOptions);
const fixture: TestFixture = component;
fixture.own(() => console.log('release request'), 'request');
await flushUpdates(() => element.element.dispatchEvent(new CustomEvent('change')));
const settleOptions = { cycles: 2, timers: false } satisfies SettleOptions;
await settle(settleOptions);
console.log(fixture.text(), element.emitted('change'), activeFixtureNames());
const autoCleanup = { assertBeforeCleanup: true } satisfies AutoCleanupOptions;
installAutoCleanup((cleanup) => { void cleanup; }, autoCleanup);
element.cleanup();
component.cleanup();
await cleanupFixtures();
assertNoFixtureLeaks();