I’m trying to write some simple unit tests with Hugo templates itself, one common case is that check if partial returned HTML contain expected elements.
{{ range $cases }}
{{ $html := partial "foobar" .input | parseHTML }}
{{/* Check if elements (attributes, text etc...) present in $html. */}}
{{/* ... */}}
{{ end }}
Some thoughts:
transform.Unmarshal
supports parsingXML
, howeverHTML
is not equal toXML
.- I’m able to implement similar tests via string functions, but not a very robust approach.
- I also manage to implement E2E tests with third party tools, like Playwright.
I think this feature will simplify testing without installing extra tools.