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 ¶
- Variables
- func AssertCommandEnqueued(t *testing.T, queue *CommandQueueInspector, count int)
- func AssertNoCommandLoop(t *testing.T, detector *LoopDetectionVerifier)
- func GetSnapshotPath(t *testing.T, name string) string
- func MatchComponentSnapshot(t *testing.T, component bubbly.Component)
- func MatchNamedSnapshot(t *testing.T, name, actual string)
- func MatchSnapshot(t *testing.T, actual string)
- func MatchSnapshotWithOptions(t *testing.T, name, actual, dir string, update bool)
- func ReadSnapshot(t *testing.T, name string) (string, error)
- func SnapshotExists(t *testing.T, name string) bool
- func UpdateSnapshots(t *testing.T) bool
- func WaitFor(t *testing.T, condition func() bool, opts WaitOptions)
- type AutoCommandTester
- type BatcherTester
- type BindTester
- type BoolRefTester
- type ChildrenManagementTester
- type CommandQueueInspector
- type ComponentTest
- type ComputedCacheVerifier
- type CustomComparatorTester
- type DataFactory
- type DeepWatchTester
- type DependencyEdge
- type DependencyGraph
- type DependencyNode
- type DependencyTrackingInspector
- type EmittedEvent
- type ErrorTesting
- type Event
- type EventInspector
- type EventTracker
- type FixtureBuilder
- type FlushModeController
- type ForEachTester
- type GenerateArgs
- type HarnessOption
- type HistoryTester
- type IfTester
- type KeyBindingsTester
- type LoopDetectionVerifier
- type LoopEvent
- type Matcher
- type MessageHandlerTester
- type MockCommand
- type MockCommandGenerator
- type MockComponent
- type MockErrorMsg
- type MockErrorReporter
- type MockFactory
- type MockRef
- type MockRouter
- type MockStorage
- type NamedRoutesTester
- type NavigationSimulator
- type NestedRoutesTester
- type NormalizePattern
- type Normalizer
- type ObservabilityAssertions
- type OnTester
- type PathMatchingTester
- type PropsMutation
- type PropsVerifier
- type ProvideInjectTester
- type QueryParamsTester
- type RouteGuardTester
- type SafetyViolation
- type ShowTester
- type SimulatedTimer
- type SnapshotManager
- type StateInspector
- type TemplateSafetyTester
- type TestHarness
- type TestHooks
- type TestIsolation
- type TestSetup
- type TimeSimulator
- type UseAsyncTester
- type UseDebounceTester
- type UseEffectTester
- type UseEventListenerTester
- type UseFormTester
- type UseLocalStorageTester
- type UseStateTester
- type UseThrottleTester
- type WaitOptions
- type WatchEffectTester
Constants ¶
This section is empty.
Variables ¶
var BeEmpty = testutil.BeEmpty
BeEmpty returns a matcher that checks for empty.
var BeNil = testutil.BeNil
BeNil returns a matcher that checks for nil.
var HaveLength = testutil.HaveLength
HaveLength returns a matcher that checks length.
var IntFactory = testutil.IntFactory
IntFactory creates an int factory.
var NewAutoCommandTester = testutil.NewAutoCommandTester
NewAutoCommandTester creates a new auto command tester.
var NewBindTester = testutil.NewBindTester
NewBindTester creates a new bind tester.
var NewBoolRefTester = testutil.NewBoolRefTester
NewBoolRefTester creates a new bool ref tester.
var NewChildrenManagementTester = testutil.NewChildrenManagementTester
NewChildrenManagementTester creates a new children management tester.
var NewComputedCacheVerifier = testutil.NewComputedCacheVerifier
NewComputedCacheVerifier creates a new computed cache verifier.
var NewCustomComparatorTester = testutil.NewCustomComparatorTester
NewCustomComparatorTester creates a new custom comparator tester.
var NewDeepWatchTester = testutil.NewDeepWatchTester
NewDeepWatchTester creates a new deep watch tester.
var NewDependencyTrackingInspector = testutil.NewDependencyTrackingInspector
NewDependencyTrackingInspector creates a new dependency tracking inspector.
var NewErrorTesting = testutil.NewErrorTesting
NewErrorTesting creates new error testing utilities.
var NewEventInspector = testutil.NewEventInspector
NewEventInspector creates a new event inspector.
var NewEventTracker = testutil.NewEventTracker
NewEventTracker creates a new event tracker.
var NewFixture = testutil.NewFixture
NewFixture creates a new fixture builder.
var NewFlushModeController = testutil.NewFlushModeController
NewFlushModeController creates a new flush mode controller.
var NewForEachTester = testutil.NewForEachTester
NewForEachTester creates a new for-each tester.
var NewIfTester = testutil.NewIfTester
NewIfTester creates a new if tester.
var NewKeyBindingsTester = testutil.NewKeyBindingsTester
NewKeyBindingsTester creates a new key bindings tester.
var NewMessageHandlerTester = testutil.NewMessageHandlerTester
NewMessageHandlerTester creates a new message handler tester.
var NewMockCommandWithError = testutil.NewMockCommandWithError
NewMockCommandWithError creates a mock command that returns an error.
var NewMockComponent = testutil.NewMockComponent
NewMockComponent creates a new mock component.
var NewMockErrorReporter = testutil.NewMockErrorReporter
NewMockErrorReporter creates a new mock error reporter.
var NewMockFactory = testutil.NewMockFactory
NewMockFactory creates a new mock factory.
var NewMockRouter = testutil.NewMockRouter
NewMockRouter creates a new mock router.
var NewMockStorage = testutil.NewMockStorage
NewMockStorage creates a new mock storage.
var NewNormalizer = testutil.NewNormalizer
NewNormalizer creates a new normalizer.
var NewObservabilityAssertions = testutil.NewObservabilityAssertions
NewObservabilityAssertions creates new observability assertions.
var NewOnTester = testutil.NewOnTester
NewOnTester creates a new on tester.
var NewPropsVerifier = testutil.NewPropsVerifier
NewPropsVerifier creates a new props verifier.
var NewProvideInjectTester = testutil.NewProvideInjectTester
NewProvideInjectTester creates a new provide/inject tester.
var NewShowTester = testutil.NewShowTester
NewShowTester creates a new show tester.
var NewSnapshotManager = testutil.NewSnapshotManager
NewSnapshotManager creates a new snapshot manager.
var NewStateInspector = testutil.NewStateInspector
NewStateInspector creates a new state inspector.
var NewTemplateSafetyTester = testutil.NewTemplateSafetyTester
NewTemplateSafetyTester creates a new template safety tester.
var NewTestHooks = testutil.NewTestHooks
NewTestHooks creates new test hooks.
var NewTestIsolation = testutil.NewTestIsolation
NewTestIsolation creates new test isolation.
var NewTestSetup = testutil.NewTestSetup
NewTestSetup creates a new test setup.
var NewTimeSimulator = testutil.NewTimeSimulator
NewTimeSimulator creates a new time simulator.
var NewUseAsyncTester = testutil.NewUseAsyncTester
NewUseAsyncTester creates a new use async tester.
var NewUseDebounceTester = testutil.NewUseDebounceTester
NewUseDebounceTester creates a new use debounce tester.
var NewUseEffectTester = testutil.NewUseEffectTester
NewUseEffectTester creates a new use effect tester.
var NewUseEventListenerTester = testutil.NewUseEventListenerTester
NewUseEventListenerTester creates a new use event listener tester.
var NewUseThrottleTester = testutil.NewUseThrottleTester
NewUseThrottleTester creates a new use throttle tester.
var NewWatchEffectTester = testutil.NewWatchEffectTester
NewWatchEffectTester creates a new watch effect tester.
var NormalizeAll = testutil.NormalizeAll
NormalizeAll applies all normalizations.
var NormalizeIDs = testutil.NormalizeIDs
NormalizeIDs normalizes generated IDs in output.
var NormalizeTimestamps = testutil.NormalizeTimestamps
NormalizeTimestamps normalizes timestamps in output.
var NormalizeUUIDs = testutil.NormalizeUUIDs
NormalizeUUIDs normalizes UUIDs in output.
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 ¶
GetSnapshotPath returns the path for a snapshot.
func MatchComponentSnapshot ¶
MatchComponentSnapshot compares a component's view against a snapshot.
func MatchNamedSnapshot ¶
MatchNamedSnapshot compares output against a named snapshot.
func MatchSnapshot ¶
MatchSnapshot compares output against a saved snapshot.
func MatchSnapshotWithOptions ¶
MatchSnapshotWithOptions compares with custom options.
func ReadSnapshot ¶
ReadSnapshot reads a snapshot from disk.
func SnapshotExists ¶
SnapshotExists checks if a snapshot exists.
func UpdateSnapshots ¶
UpdateSnapshots returns whether snapshots should be updated.
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 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 EventInspector ¶
type EventInspector = testutil.EventInspector
EventInspector inspects tracked 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 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 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 MockRef ¶
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.
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 ¶
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 ObservabilityAssertions ¶
type ObservabilityAssertions = testutil.ObservabilityAssertions
ObservabilityAssertions provides observability assertions.
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 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 TestIsolation ¶
type TestIsolation = testutil.TestIsolation
TestIsolation ensures test isolation.
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 WatchEffectTester ¶
type WatchEffectTester = testutil.WatchEffectTester
WatchEffectTester tests watchEffect behavior.