maragudk / maragudk/gomponents
Add public test helpers for rendering components
- Dominant language
- Go
- Stars
- 1.9k
- Forks
- 59
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 17
Description
Testing a component means rendering it to a string and checking the result, and every project writes the same small helper to do that:
```go
func render(t *testing.T, n Node) string {
t.Helper()
var b strings.Builder
if err := n.Render(&b); err != nil {
t.Fatal(err)
}
return b.String()
}
```
gomponents has this internally in `internal/assert`, with `assert.Equal(t, expected, node)` comparing the rendered string, but it isn't importable.
Proposal: a small public package with helpers along these lines:
- render a node to a string, failing the test on a render error
- check that the rendered output equals an expected string
- check that the rendered output contains a substring, which is what most component tests want, since pinning a whole page as one exact string breaks on every unrelated change
The package name and exact API are open. It must keep the core library free of external dependencies, which `testing` and `strings` satisfy.
This came up while writing the coding agent skill in #358, where the skill currently has to tell agents to write the render helper themselves.
Contributor guide
Research direction
Start by reading the existing helpers in internal/assert and the related coding agent skill work in issue #358. The work is complete when a public package exposes helpers for rendering nodes, comparing exact output, and checking substrings without adding dependencies beyond testing and strings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 70/100