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 ¶
- func TestID(id string) vdom.Attr
- type Config
- type Harness
- func (h *Harness) AssertActionState(m *Mounted, nameOrID string, want vango.ActionState)
- func (h *Harness) AssertExistsByTestID(m *Mounted, testid string)
- func (h *Harness) AssertNotExistsByTestID(m *Mounted, testid string)
- func (h *Harness) AssertSignal(m *Mounted, nameOrID string, want any)
- func (h *Harness) AssertSnapshot(m *Mounted, name string)
- func (h *Harness) AssertTextByTestID(m *Mounted, testid string, want string)
- func (h *Harness) AwaitAction(m *Mounted, nameOrID string)
- func (h *Harness) AwaitResource(m *Mounted, nameOrID string)
- func (h *Harness) ClickByTestID(m *Mounted, testid string)
- func (h *Harness) EmitEventByHID(m *Mounted, hid, eventType string, payload map[string]any)
- func (h *Harness) EmitEventByTestID(m *Mounted, testid, eventType string, payload map[string]any)
- func (h *Harness) ExistsByTestID(m *Mounted, testid string) bool
- func (h *Harness) Flush(m *Mounted)
- func (h *Harness) HTML(m *Mounted) string
- func (h *Harness) InputByTestID(m *Mounted, testid string, value string)
- func (h *Harness) Mount(component vango.Component) *Mounted
- func (h *Harness) SignalValue(m *Mounted, nameOrID string) any
- func (h *Harness) SubmitByTestID(m *Mounted, testid string)
- func (h *Harness) TextByTestID(m *Mounted, testid string) string
- type Mounted
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 (*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 ¶
AssertExistsByTestID asserts that an element with the given data-testid exists.
func (*Harness) AssertNotExistsByTestID ¶
AssertNotExistsByTestID asserts that no element with the given data-testid exists.
func (*Harness) AssertSignal ¶
AssertSignal asserts that a signal has the expected value.
func (*Harness) AssertSnapshot ¶
AssertSnapshot compares the rendered HTML against a stored snapshot.
func (*Harness) AssertTextByTestID ¶
AssertTextByTestID asserts that the element with the given data-testid has the expected text content.
func (*Harness) AwaitAction ¶
AwaitAction waits for an Action to reach Success or Error.
func (*Harness) AwaitResource ¶
AwaitResource waits for a Resource to reach Ready or Error.
func (*Harness) ClickByTestID ¶
ClickByTestID simulates a click event on the element with the given data-testid.
func (*Harness) EmitEventByHID ¶
EmitEventByHID simulates an event on the element with the given HID.
func (*Harness) EmitEventByTestID ¶
EmitEventByTestID simulates an event on the element with the given data-testid.
func (*Harness) ExistsByTestID ¶
ExistsByTestID returns true if an element with the given data-testid exists.
func (*Harness) Flush ¶ added in v0.2.0
Flush drains pending dispatch/effect work and rerenders dirty components.
func (*Harness) InputByTestID ¶
InputByTestID simulates an input event with the given value.
func (*Harness) SignalValue ¶
SignalValue returns the current value of a signal by debugName, stableID, or anchorKey.
func (*Harness) SubmitByTestID ¶
SubmitByTestID simulates a form submission on 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.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option configures the test harness.
func WithAwaitMaxSteps ¶
WithAwaitMaxSteps sets the maximum steps for deterministic awaits.
func WithDebugMode ¶
WithDebugMode toggles vango.DebugMode for the harness lifetime.
func WithSnapshotDir ¶
WithSnapshotDir sets a custom snapshot directory.
func WithUpdateSnapshots ¶
func WithUpdateSnapshots() Option
WithUpdateSnapshots enables snapshot update mode.