vtest

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package vtest provides a deterministic, server-side harness for testing Vango components without a browser.

The harness mounts Setup components, renders HTML, allows data-testid queries, simulates events, and provides async coordination for Resources and Actions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestID

func TestID(id string) vdom.Attr

TestID creates a data-testid attribute for querying elements in tests.

Types

type Config

type Config struct {
	PrettyHTML      bool
	SnapshotDir     string
	UpdateSnapshots bool
	DebugMode       bool
	AwaitMaxSteps   int
}

Config holds harness configuration options.

type Harness

type Harness struct {
	// contains filtered or unexported fields
}

Harness manages test sessions and component mounting.

func New

func New(t testing.TB, opts ...Option) *Harness

New creates a new test harness for the given test.

func (*Harness) AssertActionState

func (h *Harness) AssertActionState(m *Mounted, nameOrID string, want vango.ActionState)

AssertActionState asserts that an Action is in the expected state.

func (*Harness) AssertExistsByTestID

func (h *Harness) AssertExistsByTestID(m *Mounted, testid string)

AssertExistsByTestID asserts that an element with the given data-testid exists.

func (*Harness) AssertNotExistsByTestID

func (h *Harness) AssertNotExistsByTestID(m *Mounted, testid string)

AssertNotExistsByTestID asserts that no element with the given data-testid exists.

func (*Harness) AssertSignal

func (h *Harness) AssertSignal(m *Mounted, nameOrID string, want any)

AssertSignal asserts that a signal has the expected value.

func (*Harness) AssertSnapshot

func (h *Harness) AssertSnapshot(m *Mounted, name string)

AssertSnapshot compares the rendered HTML against a stored snapshot.

func (*Harness) AssertTextByTestID

func (h *Harness) AssertTextByTestID(m *Mounted, testid string, want string)

AssertTextByTestID asserts that the element with the given data-testid has the expected text content.

func (*Harness) AwaitAction

func (h *Harness) AwaitAction(m *Mounted, nameOrID string)

AwaitAction waits for an Action to reach Success or Error.

func (*Harness) AwaitResource

func (h *Harness) AwaitResource(m *Mounted, nameOrID string)

AwaitResource waits for a Resource to reach Ready or Error.

func (*Harness) ClickByTestID

func (h *Harness) ClickByTestID(m *Mounted, testid string)

ClickByTestID simulates a click event on the element with the given data-testid.

func (*Harness) EmitEventByHID

func (h *Harness) EmitEventByHID(m *Mounted, hid, eventType string, payload map[string]any)

EmitEventByHID simulates an event on the element with the given HID.

func (*Harness) EmitEventByTestID

func (h *Harness) EmitEventByTestID(m *Mounted, testid, eventType string, payload map[string]any)

EmitEventByTestID simulates an event on the element with the given data-testid.

func (*Harness) ExistsByTestID

func (h *Harness) ExistsByTestID(m *Mounted, testid string) bool

ExistsByTestID returns true if an element with the given data-testid exists.

func (*Harness) Flush added in v0.2.0

func (h *Harness) Flush(m *Mounted)

Flush drains pending dispatch/effect work and rerenders dirty components.

func (*Harness) HTML

func (h *Harness) HTML(m *Mounted) string

HTML returns the current rendered HTML of the mounted component.

func (*Harness) InputByTestID

func (h *Harness) InputByTestID(m *Mounted, testid string, value string)

InputByTestID simulates an input event with the given value.

func (*Harness) Mount

func (h *Harness) Mount(component vango.Component) *Mounted

Mount mounts a component for testing.

func (*Harness) SignalValue

func (h *Harness) SignalValue(m *Mounted, nameOrID string) any

SignalValue returns the current value of a signal by debugName, stableID, or anchorKey.

func (*Harness) SubmitByTestID

func (h *Harness) SubmitByTestID(m *Mounted, testid string)

SubmitByTestID simulates a form submission on the element with the given data-testid.

func (*Harness) TextByTestID

func (h *Harness) TextByTestID(m *Mounted, testid string) string

TextByTestID returns the text content of the element with the given data-testid.

type Mounted

type Mounted struct {
	// contains filtered or unexported fields
}

Mounted represents a mounted component tree ready for testing.

func Mount

func Mount[P any](h *Harness, component func(P) vango.Component, props P) *Mounted

Mount mounts a typed component factory with props, preserving type safety.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures the test harness.

func WithAwaitMaxSteps

func WithAwaitMaxSteps(steps int) Option

WithAwaitMaxSteps sets the maximum steps for deterministic awaits.

func WithDebugMode

func WithDebugMode(enabled bool) Option

WithDebugMode toggles vango.DebugMode for the harness lifetime.

func WithPrettyHTML

func WithPrettyHTML() Option

WithPrettyHTML enables indented HTML output.

func WithSnapshotDir

func WithSnapshotDir(dir string) Option

WithSnapshotDir sets a custom snapshot directory.

func WithUpdateSnapshots

func WithUpdateSnapshots() Option

WithUpdateSnapshots enables snapshot update mode.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL