about summary refs log tree commit diff stats
path: root/gomponents_test.go
diff options
context:
space:
mode:
authorMarkus Wüstenberg2020-12-22 10:53:22 +0100
committerGitHub2020-12-22 10:53:22 +0100
commitf22ce3fb68ca6702a683b7759410ae50a9fddabd (patch)
treeaace6553bb5c48b99d7205fe56d6b7d630b7799a /gomponents_test.go
parent428a2519eaa8e16767f86b417abd5af007f24fc6 (diff)
downloadgomponents-f22ce3fb68ca6702a683b7759410ae50a9fddabd.tar.lz
gomponents-f22ce3fb68ca6702a683b7759410ae50a9fddabd.tar.zst
gomponents-f22ce3fb68ca6702a683b7759410ae50a9fddabd.zip
Add If helper function (#57)
Used to inline conditional nodes.
Diffstat (limited to 'gomponents_test.go')
-rw-r--r--gomponents_test.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/gomponents_test.go b/gomponents_test.go
index 26199c3..c88a796 100644
--- a/gomponents_test.go
+++ b/gomponents_test.go
@@ -207,3 +207,15 @@ func TestMap(t *testing.T) {
 		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)
+	})
+}