all repos — gomponents @ 6d2fb0eeb15d6b9774f127517d160137251264a4

HTML components in pure Go

Add Group function to group Nodes (#29)

Markus Wüstenberg
commit

6d2fb0eeb15d6b9774f127517d160137251264a4

parent

f2a2b949704e2faa7117dd33aae8da551a4baf8e

1 file changed, 22 insertions(+), 0 deletions(-)

changed files
M gomponents_test.gogomponents_test.go
@@ -133,3 +133,25 @@ t.FailNow()
} }) } + +func TestGroup(t *testing.T) { + t.Run("groups multiple nodes into one", func(t *testing.T) { + children := []g.Node{g.El("div", g.Attr("id", "hat")), g.El("div")} + e := g.El("div", g.Attr("class", "foo"), g.El("div"), g.Group(children)) + assert.Equal(t, `<div class="foo"><div /><div id="hat" /><div /></div>`, e) + }) + + t.Run("panics on direct render", func(t *testing.T) { + e := g.Group(nil) + panicced := false + defer func() { + if err := recover(); err != nil { + panicced = true + } + }() + e.Render() + if !panicced { + t.FailNow() + } + }) +}