about summary refs log tree commit diff stats
path: root/gomponents_test.go
diff options
context:
space:
mode:
authorMarkus Wüstenberg2020-09-24 13:19:52 +0200
committerGitHub2020-09-24 13:19:52 +0200
commit4c109f9f1d4db4733d267ece171a533521029bdb (patch)
tree555c4ef5ad7281e8e36431d31968ade85c61aa72 /gomponents_test.go
parentf27cb0c05f23785189979e57c831eb798e1da1f1 (diff)
downloadgomponents-4c109f9f1d4db4733d267ece171a533521029bdb.tar.lz
gomponents-4c109f9f1d4db4733d267ece171a533521029bdb.tar.zst
gomponents-4c109f9f1d4db4733d267ece171a533521029bdb.zip
Introduce Placer interface (#18)
When implemented, the `Place` method of the `Placer` interface tells `Render` in `El` where to put a Node. This is relevant for helpers that want to be rendered like attributes, inside the parent element.

Fixes the bug where `attr.Classes` was rendered outside the element.
Diffstat (limited to 'gomponents_test.go')
-rw-r--r--gomponents_test.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/gomponents_test.go b/gomponents_test.go
index ee0b91d..65b82b5 100644
--- a/gomponents_test.go
+++ b/gomponents_test.go
@@ -52,6 +52,12 @@ func TestAttr(t *testing.T) {
 	})
 }
 
+type outsider struct{}
+
+func (o outsider) Render() string {
+	return "outsider"
+}
+
 func TestEl(t *testing.T) {
 	t.Run("renders an empty element if no children given", func(t *testing.T) {
 		e := g.El("div")
@@ -72,6 +78,11 @@ func TestEl(t *testing.T) {
 		e := g.El("div", g.El("span"), g.Attr("class", "hat"))
 		assert.Equal(t, `<div class="hat"><span/></div>`, e)
 	})
+
+	t.Run("renders outside if node does not implement placer", func(t *testing.T) {
+		e := g.El("div", outsider{})
+		assert.Equal(t, `<div>outsider</div>`, e)
+	})
 }
 
 func TestText(t *testing.T) {