package h import ( "github.com/stretchr/testify/assert" "testing" ) func TestRender(t *testing.T) { div := Div( Id("my-div"), Attribute("data-attr-2", "value"), Attributes(&AttributeMap{ "data-attr-3": "value", "data-attr-4": "value", }), BeforeRequest( SetText("before request"), ), AfterRequest( SetText("after request"), ), Children( Div(Text("hello, world")), ), Text("hello, child"), ) div.attributes["data-attr-1"] = "value" result := Render(div) assert.Equal(t, `
hello, world
hello, child
`, result) } func TestRawContent(t *testing.T) { str := "
hello, world
" raw := Raw(str) assert.Equal(t, str, Render(raw)) } func TestConditional(t *testing.T) { result := Render( Div( IfElse(true, Text("true"), Text("false")), ), ) assert.Equal(t, "
true
", result) result = Render( Div( If(false, Text("true")), ), ) assert.Equal(t, "
", result) }