all repos — gomponents @ f22ce3fb68ca6702a683b7759410ae50a9fddabd

HTML components in pure Go

Add If helper function (#57) Used to inline conditional nodes.

Markus Wüstenberg
commit

f22ce3fb68ca6702a683b7759410ae50a9fddabd

parent

428a2519eaa8e16767f86b417abd5af007f24fc6

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

changed files
M gomponents_test.gogomponents_test.go
@@ -207,3 +207,15 @@
assert.Equal(t, `<ul><li>hat</li><li>partyhat</li><li>turtlehat</li></ul>`, list) }) } + +func TestIf(t *testing.T) { + t.Run("returns node if condition is true", func(t *testing.T) { + n := g.El("div", g.If(true, g.El("span"))) + assert.Equal(t, "<div><span></span></div>", n) + }) + + t.Run("returns nil if condition is false", func(t *testing.T) { + n := g.El("div", g.If(false, g.El("span"))) + assert.Equal(t, "<div></div>", n) + }) +}