testutil

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package testutil provides comprehensive test utilities for BubblyUI applications.

This package contains testers, mocks, assertions, simulators, and snapshot testing utilities for thorough BubblyUI component and composable testing.

This package is an alias for github.com/newbpydev/bubblyui/pkg/bubbly/testutil, providing a cleaner import path for users.

Features

  • Component testers for all built-in features
  • Mock implementations (Ref, Router, Storage, etc.)
  • Snapshot testing with diff visualization
  • Time simulation for async testing
  • Event tracking and inspection
  • Command queue inspection
  • Data factories for test fixtures

Example

import "github.com/newbpydev/bubblyui/testing/testutil"

func TestComponent(t *testing.T) {
    // Create harness
    h := testutil.NewHarness(t)

    // Create mock ref
    ref := testutil.NewMockRef(42)

    // Snapshot testing
    testutil.MatchSnapshot(t, component.View())
}

Index

Constants

This section is empty.

Variables

View Source
var BeEmpty = testutil.BeEmpty

BeEmpty returns a matcher that checks for empty.

View Source
var BeNil = testutil.BeNil

BeNil returns a matcher that checks for nil.

View Source
var HaveLength = testutil.HaveLength

HaveLength returns a matcher that checks length.

View Source
var IntFactory = testutil.IntFactory

IntFactory creates an int factory.

View Source
var NewAutoCommandTester = testutil.NewAutoCommandTester

NewAutoCommandTester creates a new auto command tester.

View Source
var NewBindTester = testutil.NewBindTester

NewBindTester creates a new bind tester.

View Source
var NewBoolRefTester = testutil.NewBoolRefTester

NewBoolRefTester creates a new bool ref tester.

View Source
var NewChildrenManagementTester = testutil.NewChildrenManagementTester

NewChildrenManagementTester creates a new children management tester.

View Source
var NewComputedCacheVerifier = testutil.NewComputedCacheVerifier

NewComputedCacheVerifier creates a new computed cache verifier.

View Source
var NewCustomComparatorTester = testutil.NewCustomComparatorTester

NewCustomComparatorTester creates a new custom comparator tester.

View Source
var NewDeepWatchTester = testutil.NewDeepWatchTester

NewDeepWatchTester creates a new deep watch tester.

View Source
var NewDependencyTrackingInspector = testutil.NewDependencyTrackingInspector

NewDependencyTrackingInspector creates a new dependency tracking inspector.

View Source
var NewErrorTesting = testutil.NewErrorTesting

NewErrorTesting creates new error testing utilities.

View Source
var NewEventInspector = testutil.NewEventInspector

NewEventInspector creates a new event inspector.

View Source
var NewEventTracker = testutil.NewEventTracker

NewEventTracker creates a new event tracker.

View Source
var NewFixture = testutil.NewFixture

NewFixture creates a new fixture builder.

View Source
var NewFlushModeController = testutil.NewFlushModeController

NewFlushModeController creates a new flush mode controller.

View Source
var NewForEachTester = testutil.NewForEachTester

NewForEachTester creates a new for-each tester.

View Source
var NewIfTester = testutil.NewIfTester

NewIfTester creates a new if tester.

View Source
var NewKeyBindingsTester = testutil.NewKeyBindingsTester

NewKeyBindingsTester creates a new key bindings tester.

View Source
var NewMessageHandlerTester = testutil.NewMessageHandlerTester

NewMessageHandlerTester creates a new message handler tester.

View Source
var NewMockCommandWithError = testutil.NewMockCommandWithError

NewMockCommandWithError creates a mock command that returns an error.

View Source
var NewMockComponent = testutil.NewMockComponent

NewMockComponent creates a new mock component.

View Source
var NewMockErrorReporter = testutil.NewMockErrorReporter

NewMockErrorReporter creates a new mock error reporter.

View Source
var NewMockFactory = testutil.NewMockFactory

NewMockFactory creates a new mock factory.

View Source
var NewMockRouter = testutil.NewMockRouter

NewMockRouter creates a new mock router.

View Source
var NewMockStorage = testutil.NewMockStorage

NewMockStorage creates a new mock storage.

View Source
var NewNormalizer = testutil.NewNormalizer

NewNormalizer creates a new normalizer.

View Source
var NewObservabilityAssertions = testutil.NewObservabilityAssertions

NewObservabilityAssertions creates new observability assertions.

View Source
var NewOnTester = testutil.NewOnTester

NewOnTester creates a new on tester.

View Source
var NewPropsVerifier = testutil.NewPropsVerifier

NewPropsVerifier creates a new props verifier.

View Source
var NewProvideInjectTester = testutil.NewProvideInjectTester

NewProvideInjectTester creates a new provide/inject tester.

View Source
var NewShowTester = testutil.NewShowTester

NewShowTester creates a new show tester.

View Source
var NewSnapshotManager = testutil.NewSnapshotManager

NewSnapshotManager creates a new snapshot manager.

View Source
var NewStateInspector = testutil.NewStateInspector

NewStateInspector creates a new state inspector.

View Source
var NewTemplateSafetyTester = testutil.NewTemplateSafetyTester

NewTemplateSafetyTester creates a new template safety tester.

View Source
var NewTestHooks = testutil.NewTestHooks

NewTestHooks creates new test hooks.

View Source
var NewTestIsolation = testutil.NewTestIsolation

NewTestIsolation creates new test isolation.

View Source
var NewTestSetup = testutil.NewTestSetup

NewTestSetup creates a new test setup.

View Source
var NewTimeSimulator = testutil.NewTimeSimulator

NewTimeSimulator creates a new time simulator.

View Source
var NewUseAsyncTester = testutil.NewUseAsyncTester

NewUseAsyncTester creates a new use async tester.

View Source
var NewUseDebounceTester = testutil.NewUseDebounceTester

NewUseDebounceTester creates a new use debounce tester.

View Source
var NewUseEffectTester = testutil.NewUseEffectTester

NewUseEffectTester creates a new use effect tester.

View Source
var NewUseEventListenerTester = testutil.NewUseEventListenerTester

NewUseEventListenerTester creates a new use event listener tester.

View Source
var NewUseThrottleTester = testutil.NewUseThrottleTester

NewUseThrottleTester creates a new use throttle tester.

View Source
var NewWatchEffectTester = testutil.NewWatchEffectTester

NewWatchEffectTester creates a new watch effect tester.

View Source
var NormalizeAll = testutil.NormalizeAll

NormalizeAll applies all normalizations.

View Source
var NormalizeIDs = testutil.NormalizeIDs

NormalizeIDs normalizes generated IDs in output.

View Source
var NormalizeTimestamps = testutil.NormalizeTimestamps

NormalizeTimestamps normalizes timestamps in output.

View Source
var NormalizeUUIDs = testutil.NormalizeUUIDs

NormalizeUUIDs normalizes UUIDs in output.

View Source
var StringFactory = testutil.StringFactory

StringFactory creates a string factory.

Functions

func AssertCommandEnqueued

func AssertCommandEnqueued(t *testing.T, queue *CommandQueueInspector, count int)

AssertCommandEnqueued asserts that commands were enqueued.

func AssertNoCommandLoop

func AssertNoCommandLoop(t *testing.T, detector *LoopDetectionVerifier)

AssertNoCommandLoop asserts no command loop occurred.

func GetSnapshotPath

func GetSnapshotPath(t *testing.T, name string) string

GetSnapshotPath returns the path for a snapshot.

func MatchComponentSnapshot

func MatchComponentSnapshot(t *testing.T, component bubbly.Component)

MatchComponentSnapshot compares a component's view against a snapshot.

func MatchNamedSnapshot

func MatchNamedSnapshot(t *testing.T, name, actual string)

MatchNamedSnapshot compares output against a named snapshot.

func MatchSnapshot

func MatchSnapshot(t *testing.T, actual string)

MatchSnapshot compares output against a saved snapshot.

func MatchSnapshotWithOptions

func MatchSnapshotWithOptions(t *testing.T, name, actual, dir string, update bool)

MatchSnapshotWithOptions compares with custom options.

func ReadSnapshot

func ReadSnapshot(t *testing.T, name string) (string, error)

ReadSnapshot reads a snapshot from disk.

func SnapshotExists

func SnapshotExists(t *testing.T, name string) bool

SnapshotExists checks if a snapshot exists.

func UpdateSnapshots

func UpdateSnapshots(t *testing.T) bool

UpdateSnapshots returns whether snapshots should be updated.

func WaitFor

func WaitFor(t *testing.T, condition func() bool, opts WaitOptions)

WaitFor waits for a condition to be true.

Types

type AutoCommandTester

type AutoCommandTester = testutil.AutoCommandTester

AutoCommandTester tests automatic command generation.

type BatcherTester

type BatcherTester = testutil.BatcherTester

BatcherTester tests command batching.

func NewBatcherTester

func NewBatcherTester(batcher *commands.CommandBatcher) *BatcherTester

NewBatcherTester creates a new batcher tester.

type BindTester

type BindTester = testutil.BindTester

BindTester tests v-bind directive behavior.

type BoolRefTester

type BoolRefTester = testutil.BoolRefTester

BoolRefTester tests boolean ref behavior.

type ChildrenManagementTester

type ChildrenManagementTester = testutil.ChildrenManagementTester

ChildrenManagementTester tests children management.

type CommandQueueInspector

type CommandQueueInspector = testutil.CommandQueueInspector

CommandQueueInspector inspects command queues.

func NewCommandQueueInspector

func NewCommandQueueInspector(queue *bubbly.CommandQueue) *CommandQueueInspector

NewCommandQueueInspector creates a new command queue inspector.

type ComponentTest

type ComponentTest = testutil.ComponentTest

ComponentTest is a base for component tests.

type ComputedCacheVerifier

type ComputedCacheVerifier = testutil.ComputedCacheVerifier

ComputedCacheVerifier verifies computed caching.

type CustomComparatorTester

type CustomComparatorTester = testutil.CustomComparatorTester

CustomComparatorTester tests custom comparator behavior.

type DataFactory

type DataFactory[T any] = testutil.DataFactory[T]

DataFactory generates test data.

func NewFactory

func NewFactory[T any](generator func() T) *DataFactory[T]

NewFactory creates a new data factory.

type DeepWatchTester

type DeepWatchTester = testutil.DeepWatchTester

DeepWatchTester tests deep watch behavior.

type DependencyEdge

type DependencyEdge = testutil.DependencyEdge

DependencyEdge represents an edge in the dependency graph.

type DependencyGraph

type DependencyGraph = testutil.DependencyGraph

DependencyGraph represents a dependency graph.

type DependencyNode

type DependencyNode = testutil.DependencyNode

DependencyNode represents a node in the dependency graph.

type DependencyTrackingInspector

type DependencyTrackingInspector = testutil.DependencyTrackingInspector

DependencyTrackingInspector inspects dependency tracking.

type EmittedEvent

type EmittedEvent = testutil.EmittedEvent

EmittedEvent represents an emitted event.

type ErrorTesting

type ErrorTesting = testutil.ErrorTesting

ErrorTesting provides error testing utilities.

type Event

type Event = testutil.Event

Event represents a tracked event.

type EventInspector

type EventInspector = testutil.EventInspector

EventInspector inspects tracked events.

type EventTracker

type EventTracker = testutil.EventTracker

EventTracker tracks events.

type FixtureBuilder

type FixtureBuilder = testutil.FixtureBuilder

FixtureBuilder builds test fixtures.

type FlushModeController

type FlushModeController = testutil.FlushModeController

FlushModeController controls flush modes for testing.

type ForEachTester

type ForEachTester = testutil.ForEachTester

ForEachTester tests v-for directive behavior.

type GenerateArgs

type GenerateArgs = testutil.GenerateArgs

GenerateArgs configures data generation.

type HarnessOption

type HarnessOption = testutil.HarnessOption

HarnessOption configures a test harness.

type HistoryTester

type HistoryTester = testutil.HistoryTester

HistoryTester tests router history.

func NewHistoryTester

func NewHistoryTester(r *router.Router) *HistoryTester

NewHistoryTester creates a new history tester.

type IfTester

type IfTester = testutil.IfTester

IfTester tests v-if directive behavior.

type KeyBindingsTester

type KeyBindingsTester = testutil.KeyBindingsTester

KeyBindingsTester tests key bindings.

type LoopDetectionVerifier

type LoopDetectionVerifier = testutil.LoopDetectionVerifier

LoopDetectionVerifier verifies loop detection.

func NewLoopDetectionVerifier

func NewLoopDetectionVerifier(detector *commands.LoopDetector) *LoopDetectionVerifier

NewLoopDetectionVerifier creates a new loop detection verifier.

type LoopEvent

type LoopEvent = testutil.LoopEvent

LoopEvent represents a detected loop event.

type Matcher

type Matcher = testutil.Matcher

Matcher is the interface for custom matchers.

type MessageHandlerTester

type MessageHandlerTester = testutil.MessageHandlerTester

MessageHandlerTester tests message handlers.

type MockCommand

type MockCommand = testutil.MockCommand

MockCommand is a mock command for testing.

func NewMockCommand

func NewMockCommand(msg tea.Msg) (*MockCommand, tea.Cmd)

NewMockCommand creates a new mock command.

type MockCommandGenerator

type MockCommandGenerator = testutil.MockCommandGenerator

MockCommandGenerator is a mock command generator.

func NewMockCommandGenerator

func NewMockCommandGenerator(returnCmd tea.Cmd) *MockCommandGenerator

NewMockCommandGenerator creates a new mock command generator.

type MockComponent

type MockComponent = testutil.MockComponent

MockComponent is a mock component for testing.

type MockErrorMsg

type MockErrorMsg = testutil.MockErrorMsg

MockErrorMsg represents a mock error message.

type MockErrorReporter

type MockErrorReporter = testutil.MockErrorReporter

MockErrorReporter is a mock error reporter for testing.

type MockFactory

type MockFactory = testutil.MockFactory

MockFactory manages mock refs.

type MockRef

type MockRef[T any] = testutil.MockRef[T]

MockRef is a mock implementation of Ref for testing.

func CreateMockRef

func CreateMockRef[T any](mf *MockFactory, name string, initial T) *MockRef[T]

CreateMockRef creates a mock ref in a factory.

func GetMockRef

func GetMockRef[T any](mf *MockFactory, name string) *MockRef[T]

GetMockRef gets a mock ref from a factory.

func NewMockRef

func NewMockRef[T any](initial T) *MockRef[T]

NewMockRef creates a new mock ref.

type MockRouter

type MockRouter = testutil.MockRouter

MockRouter is a mock router for testing.

type MockStorage

type MockStorage = testutil.MockStorage

MockStorage is a mock storage for testing.

type NamedRoutesTester

type NamedRoutesTester = testutil.NamedRoutesTester

NamedRoutesTester tests named routes.

func NewNamedRoutesTester

func NewNamedRoutesTester(r *router.Router) *NamedRoutesTester

NewNamedRoutesTester creates a new named routes tester.

type NavigationSimulator = testutil.NavigationSimulator

NavigationSimulator simulates navigation.

func NewNavigationSimulator

func NewNavigationSimulator(r *router.Router) *NavigationSimulator

NewNavigationSimulator creates a new navigation simulator.

type NestedRoutesTester

type NestedRoutesTester = testutil.NestedRoutesTester

NestedRoutesTester tests nested routes.

func NewNestedRoutesTester

func NewNestedRoutesTester(r *router.Router) *NestedRoutesTester

NewNestedRoutesTester creates a new nested routes tester.

type NormalizePattern

type NormalizePattern = testutil.NormalizePattern

NormalizePattern defines a normalization pattern.

type Normalizer

type Normalizer = testutil.Normalizer

Normalizer applies custom normalizations.

type ObservabilityAssertions

type ObservabilityAssertions = testutil.ObservabilityAssertions

ObservabilityAssertions provides observability assertions.

type OnTester

type OnTester = testutil.OnTester

OnTester tests v-on directive behavior.

type PathMatchingTester

type PathMatchingTester = testutil.PathMatchingTester

PathMatchingTester tests path matching.

func NewPathMatchingTester

func NewPathMatchingTester(r *router.Router) *PathMatchingTester

NewPathMatchingTester creates a new path matching tester.

type PropsMutation

type PropsMutation = testutil.PropsMutation

PropsMutation represents a props mutation.

type PropsVerifier

type PropsVerifier = testutil.PropsVerifier

PropsVerifier verifies component props.

type ProvideInjectTester

type ProvideInjectTester = testutil.ProvideInjectTester

ProvideInjectTester tests provide/inject behavior.

type QueryParamsTester

type QueryParamsTester = testutil.QueryParamsTester

QueryParamsTester tests query parameters.

func NewQueryParamsTester

func NewQueryParamsTester(r *router.Router) *QueryParamsTester

NewQueryParamsTester creates a new query params tester.

type RouteGuardTester

type RouteGuardTester = testutil.RouteGuardTester

RouteGuardTester tests route guards.

func NewRouteGuardTester

func NewRouteGuardTester(r *router.Router) *RouteGuardTester

NewRouteGuardTester creates a new route guard tester.

type SafetyViolation

type SafetyViolation = testutil.SafetyViolation

SafetyViolation represents a safety violation.

type ShowTester

type ShowTester = testutil.ShowTester

ShowTester tests v-show directive behavior.

type SimulatedTimer

type SimulatedTimer = testutil.SimulatedTimer

SimulatedTimer is a simulated timer.

type SnapshotManager

type SnapshotManager = testutil.SnapshotManager

SnapshotManager manages snapshots.

func GetSnapshotManager

func GetSnapshotManager(t *testing.T) *SnapshotManager

GetSnapshotManager returns the snapshot manager for a test.

type StateInspector

type StateInspector = testutil.StateInspector

StateInspector inspects component state.

type TemplateSafetyTester

type TemplateSafetyTester = testutil.TemplateSafetyTester

TemplateSafetyTester tests template safety.

type TestHarness

type TestHarness = testutil.TestHarness

TestHarness provides a complete test environment.

func NewHarness

func NewHarness(t *testing.T, opts ...HarnessOption) *TestHarness

NewHarness creates a new test harness.

type TestHooks

type TestHooks = testutil.TestHooks

TestHooks provides test lifecycle hooks.

type TestIsolation

type TestIsolation = testutil.TestIsolation

TestIsolation ensures test isolation.

type TestSetup

type TestSetup = testutil.TestSetup

TestSetup provides common test setup utilities.

type TimeSimulator

type TimeSimulator = testutil.TimeSimulator

TimeSimulator simulates time for testing async behavior.

type UseAsyncTester

type UseAsyncTester = testutil.UseAsyncTester

UseAsyncTester tests useAsync behavior.

type UseDebounceTester

type UseDebounceTester = testutil.UseDebounceTester

UseDebounceTester tests useDebounce behavior.

type UseEffectTester

type UseEffectTester = testutil.UseEffectTester

UseEffectTester tests useEffect behavior.

type UseEventListenerTester

type UseEventListenerTester = testutil.UseEventListenerTester

UseEventListenerTester tests useEventListener behavior.

type UseFormTester

type UseFormTester[T any] = testutil.UseFormTester[T]

UseFormTester tests useForm behavior.

func NewUseFormTester

func NewUseFormTester[T any](comp bubbly.Component) *UseFormTester[T]

NewUseFormTester creates a new use form tester.

type UseLocalStorageTester

type UseLocalStorageTester[T any] = testutil.UseLocalStorageTester[T]

UseLocalStorageTester tests useLocalStorage behavior.

func NewUseLocalStorageTester

func NewUseLocalStorageTester[T any](comp bubbly.Component, storage composables.Storage) *UseLocalStorageTester[T]

NewUseLocalStorageTester creates a new use local storage tester.

type UseStateTester

type UseStateTester[T any] = testutil.UseStateTester[T]

UseStateTester tests useState behavior.

func NewUseStateTester

func NewUseStateTester[T any](comp bubbly.Component) *UseStateTester[T]

NewUseStateTester creates a new use state tester.

type UseThrottleTester

type UseThrottleTester = testutil.UseThrottleTester

UseThrottleTester tests useThrottle behavior.

type WaitOptions

type WaitOptions = testutil.WaitOptions

WaitOptions configures WaitFor behavior.

type WatchEffectTester

type WatchEffectTester = testutil.WatchEffectTester

WatchEffectTester tests watchEffect behavior.

Jump to

Keyboard shortcuts

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