From f9d584c9889276000171046bcc2e32177514f552 Mon Sep 17 00:00:00 2001 From: Markus Wüstenberg Date: Fri, 18 Sep 2020 14:38:09 +0200 Subject: Make NodeFunc and attr implement fmt.Stringer (#6) --- gomponents_test.go | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'gomponents_test.go') diff --git a/gomponents_test.go b/gomponents_test.go index 21ab30a..fdc8c52 100644 --- a/gomponents_test.go +++ b/gomponents_test.go @@ -4,17 +4,27 @@ import ( "testing" g "github.com/maragudk/gomponents" + "github.com/maragudk/gomponents/assert" ) +func TestNodeFunc(t *testing.T) { + t.Run("implements fmt.Stringer", func(t *testing.T) { + fn := g.NodeFunc(func() string { return "hat" }) + if fn.String() != "hat" { + t.FailNow() + } + }) +} + func TestAttr(t *testing.T) { t.Run("renders just the local name with one argument", func(t *testing.T) { a := g.Attr("required") - equal(t, " required", a.Render()) + assert.Equal(t, " required", a) }) t.Run("renders the name and value when given two arguments", func(t *testing.T) { a := g.Attr("id", "hat") - equal(t, ` id="hat"`, a.Render()) + assert.Equal(t, ` id="hat"`, a) }) t.Run("panics with more than two arguments", func(t *testing.T) { @@ -34,42 +44,35 @@ func TestAttr(t *testing.T) { func TestEl(t *testing.T) { t.Run("renders an empty element if no children given", func(t *testing.T) { e := g.El("div") - equal(t, "
", e.Render()) + assert.Equal(t, "", e) }) t.Run("renders an empty element if only attributes given as children", func(t *testing.T) { e := g.El("div", g.Attr("class", "hat")) - equal(t, ``, e.Render()) + assert.Equal(t, ``, e) }) t.Run("renders an element, attributes, and element children", func(t *testing.T) { e := g.El("div", g.Attr("class", "hat"), g.El("span")) - equal(t, `