Skip to content

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

TemplateTypes

A string of HTML or a lit-html template created using the html tag.

options?

FixtureRenderOptions

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&lt;HTMLButtonElement&gt;(html`&lt;button&gt;Click me&lt;/button&gt;`)
  assert.equal(el.textContent, 'Click me')
})

test('renders string template', async ({ assert }) => {
  const el = await fixture&lt;HTMLDivElement&gt;('<div id="test"></div>')
  assert.equal(el.id, 'test')
})