MCPcopy Create free account
hub / github.com/BryanMwangi/pine / TestRender_HTML_SharedPartial

Function TestRender_HTML_SharedPartial

render/engine_test.go:107–129  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

105}
106
107func TestRender_HTML_SharedPartial(t *testing.T) {
108 dir := makeViewDir(t, map[string]string{
109 "nav.html": `{{define "nav"}}<nav>Menu</nav>{{end}}`,
110 "index.html": `{{template "nav" .}}<main>{{.Body}}</main>`,
111 })
112
113 server := setupServer(t, dir)
114 server.Get("/", func(c *pine.Ctx) error {
115 return c.Render("index.html", map[string]string{"Body": "content"})
116 })
117
118 req := httptest.NewRequest(http.MethodGet, "/", nil)
119 rr := httptest.NewRecorder()
120 server.ServeHTTP(rr, req)
121
122 body := rr.Body.String()
123 if !strings.Contains(body, "<nav>Menu</nav>") {
124 t.Errorf("expected nav partial in body, got %q", body)
125 }
126 if !strings.Contains(body, "<main>content</main>") {
127 t.Errorf("expected main content in body, got %q", body)
128 }
129}
130
131func TestRender_NoEngine_ReturnsError(t *testing.T) {
132 server := pine.New() // no engine configured

Callers

nothing calls this directly

Calls 5

makeViewDirFunction · 0.85
setupServerFunction · 0.85
ServeHTTPMethod · 0.80
RenderMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected