Lupa API Reference / testing/fixture / fixture
Function: fixture()
fixture<
T>(template,options?):Promise<T>
Defined in: src/testing/fixture.ts:59
Renders a HTML string or a Lit template into a dedicated fixture container and mounts it to the DOM.
The fixture is automatically cleaned up and removed from the DOM when the current test or group finishes.
Type Parameters
T
T extends Element = Element
Parameters
template
A string of HTML or a lit-html template created using the html tag.
options?
Returns
Promise<T>
A promise that resolves to the rendered DOM Element.
Use When
Rendering templates and Custom Elements into the DOM for interaction
Avoid When
Testing pure logic or functions that do not require a DOM
Example
ts
test('renders lit template', async ({ assert }) => {
const el = await fixture<HTMLButtonElement>(html`<button>Click me</button>`)
assert.equal(el.textContent, 'Click me')
})
test('renders string template', async ({ assert }) => {
const el = await fixture<HTMLDivElement>('<div id="test"></div>')
assert.equal(el.id, 'test')
})