Skip to content

Lupa API Reference / @pawel-up/lupa/testing / TestContext

Class: TestContext

Defined in: src/testing/test_context.ts:10

A fresh copy of test context is shared with all the tests. Note, this runs in the browser context.

Extends

  • default

Constructors

Constructor

new TestContext(test): TestContext

Defined in: src/testing/test_context.ts:34

Parameters

test

Test

Returns

TestContext

Overrides

Macroable.constructor

DOM

fixture

fixture: <T>(template, options?) => Promise<T>

Defined in: src/testing/test_context.ts:32

Renders a HTML string or a Lit template into a dedicated fixture container and mounts it to the DOM. Bound explicitly to this test context instance for auto-cleanup.

Type Parameters

T

T extends Element = Element

Parameters

template

TemplateTypes

A string of HTML or a lit-html template.

options?

FixtureRenderOptions

Render options.

Returns

Promise<T>

A promise resolving to the rendered DOM element.

Use When

Rendering HTML templates or Custom Elements into the DOM in a test.

Example

ts
test('renders lit template', async ({ fixture, assert }) => {
  const el = await fixture&lt;HTMLButtonElement&gt;(html`&lt;button&gt;Click me&lt;/button&gt;`)
  assert.equal(el.textContent, 'Click me')
})

Other

assert

assert: Assert

Defined in: src/assert/index.ts:25


cleanup

cleanup: (cleanupCallback) => void

Defined in: src/testing/test_context.ts:11

Parameters

cleanupCallback

TestHooksCleanupHandler

Returns

void


module

module: ModuleMock

Defined in: src/module-mock/fixture.ts:119


network

network: Network

Defined in: src/network/index.ts:277


test

test: Test

Defined in: src/testing/test_context.ts:34


browserName

Get Signature

get browserName(): "chromium" | "firefox" | "webkit"

Defined in: src/testing/test_context.ts:55

The name of the browser in which the current test is executing.

Automatically resolves from Lupa orchestrator context configuration, or falls back to basic user-agent analysis if window.lupa configuration is missing.

Returns

"chromium" | "firefox" | "webkit"


getter()

static getter<T, K>(this, name, accumulator, singleton?): void

Defined in: node_modules/@poppinss/macroable/build/index.d.ts:112

Adds a getter property to the class prototype using Object.defineProperty. Getters are computed properties that are evaluated each time they are accessed, unless the singleton flag is enabled.

Type Parameters

T

T extends (...args) => any

K

K extends string | number | symbol

Parameters

this

T

name

K

The name of the getter property

accumulator

() => InstanceType<T>[K]

Function that computes and returns the property value

singleton?

boolean

If true, the getter value is cached after first access

Returns

void

Example

ts
// Add a regular getter
MyClass.getter('timestamp', function() {
  return Date.now()
})

// Add a singleton getter (cached after first access)
MyClass.getter('config', function() {
  return loadConfig()
}, true)

const instance = new MyClass()
instance.timestamp // Computed each time
instance.config // Computed once, then cached

Inherited from

Macroable.getter


instanceProperty()

static instanceProperty<T, K>(this, name, value): void

Defined in: node_modules/@poppinss/macroable/build/index.d.ts:83

Adds an instance property that will be assigned to each instance during construction. Unlike macros which are added to the prototype, instance properties are unique to each instance.

Type Parameters

T

T extends (...args) => any

K

K extends string | number | symbol

Parameters

this

T

name

K

The name of the property to add to instances

value

InstanceType<T>[K]

The value to assign to the property on each instance

Returns

void

Example

ts
// Add an instance method
MyClass.instanceProperty('save', function() {
  console.log('Saving...', this.id)
})

const { save } = new MyClass()
save()

Inherited from

Macroable.instanceProperty


macro()

static macro<T, K>(this, name, value): void

Defined in: node_modules/@poppinss/macroable/build/index.d.ts:62

Adds a macro (property or method) to the class prototype. Macros are standard properties that get added to the class prototype, making them available on all instances of the class.

Type Parameters

T

T extends (...args) => any

K

K extends string | number | symbol

Parameters

this

T

name

K

The name of the property or method to add

value

InstanceType<T>[K]

The value to assign to the property or method

Returns

void

Example

ts
// Add a property macro
MyClass.macro('version', '1.0.0')

// Add a method macro
MyClass.macro('greet', function() {
  return 'Hello!'
})

const instance = new MyClass()
instance.version // "1.0.0"
instance.greet() // "Hello!"

Inherited from

Macroable.macro