go-html/cmd/wasm/register_test.go
Claude dcd55a434c
feat(wasm): add registerComponents export for WC codegen
Exposes gohtml.registerComponents(slotsJSON) to browser context.
Pure-Go buildComponentJS is testable without WASM; WASM glue uses
Function constructor for browser-side execution.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 20:50:50 +00:00

24 lines
541 B
Go

//go:build !js
package main
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestBuildComponentJS_Good(t *testing.T) {
slotsJSON := `{"H":"nav-bar","C":"main-content"}`
js, err := buildComponentJS(slotsJSON)
require.NoError(t, err)
assert.Contains(t, js, "NavBar")
assert.Contains(t, js, "MainContent")
assert.Contains(t, js, "customElements.define")
}
func TestBuildComponentJS_Bad_InvalidJSON(t *testing.T) {
_, err := buildComponentJS("not json")
assert.Error(t, err)
}