Documentation
¶
Overview ¶
Package htmlctest provides helpers for testing htmlc components.
It is intended for use in *_test.go files. The helpers reduce the boilerplate of creating an in-memory filesystem, wiring up an Engine, and asserting on rendered HTML output.
Example:
func TestGreeting(t *testing.T) {
e := htmlctest.NewEngine(t, map[string]string{
"Greeting.vue": `<template><p>Hello {{ name }}!</p></template>`,
})
htmlctest.AssertFragment(t, e, "Greeting",
map[string]any{"name": "World"},
"<p>Hello World!</p>",
)
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertFragment ¶
AssertFragment asserts that rendering name as an HTML fragment with data produces HTML equal to want (after normalising whitespace).
func AssertRendersHTML ¶
func AssertRendersHTML(t testing.TB, e *htmlc.Engine, name string, data map[string]any, want string)
AssertRendersHTML asserts that rendering name as a full HTML page with data produces HTML equal to want (after normalising whitespace).
func NewEngine ¶
NewEngine creates a test Engine backed by an in-memory filesystem built from files. The keys of files are file paths (e.g. "Button.vue") and the values are their contents.
If any option is provided via opts it replaces the default Options; the FS and ComponentDir fields are always overridden by the in-memory filesystem.
t.Cleanup is registered to satisfy the testing.TB contract; no goroutines are started so there is nothing to clean up at this time — the hook is reserved for future use.
Types ¶
This section is empty.