Add element helpers and refactor (#34) This change adds a lot of element helpers, and refactors: - helpers into simple, text, and other helpers - most tests into table-driven tests, so they're easier to read Thanks to @oderwat for pushing me to improve the tests. 😉
1 file changed, 15 insertions(+), 3 deletions(-)
changed files
M el/form_test.go → el/elements_test.go
@@ -8,9 +8,9 @@ "github.com/maragudk/gomponents/assert" "github.com/maragudk/gomponents/el" ) -func TestButton(t *testing.T) { - t.Run("returns a button element", func(t *testing.T) { - assert.Equal(t, `<button />`, el.Button()) +func TestDocument(t *testing.T) { + t.Run("returns doctype and children", func(t *testing.T) { + assert.Equal(t, `<!doctype html><html />`, el.Document(g.El("html"))) }) }@@ -56,3 +56,15 @@ t.Run("returns a textarea element with attribute name", func(t *testing.T) { assert.Equal(t, `<textarea name="hat" />`, el.Textarea("hat")) }) } + +func TestA(t *testing.T) { + t.Run("returns an a element with a href attribute", func(t *testing.T) { + assert.Equal(t, `<a href="#">hat</a>`, el.A("#", g.Text("hat"))) + }) +} + +func TestImg(t *testing.T) { + t.Run("returns an img element with href and alt attributes", func(t *testing.T) { + assert.Equal(t, `<img src="hat.png" alt="hat" id="image" />`, el.Img("hat.png", "hat", g.Attr("id", "image"))) + }) +}