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>
24 lines
541 B
Go
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)
|
|
}
|