Skip to content

test: add view render coverage for View.Make, View.First and Template.Render (framework#1594) - #163

Merged
hwbrzzl merged 1 commit into
masterfrom
ship/2026-10-27-example-view-render-tests
Oct 27, 2026
Merged

hwbrzzl merged 1 commit into
masterfrom
ship/2026-10-27-example-view-render-tests

Conversation

@goravel-agent

Copy link
Copy Markdown
Contributor

Summary

  • View.Make, View.First and Template.Render now have feature coverage that renders views with no HTTP request in scope: request-bound values such as csrf_token come out empty, while nested templates and path-named files still resolve.
  • Package views are exercised end to end: a views directory registered through LoadViewsFrom renders next to app views, and resources/views still wins over an identical define name in a package.
  • View.First is pinned to its full contract: missing and define-only files are skipped instead of returned, no renderable candidate surfaces as errors.ViewNoneExist, and unusable data surfaces as errors.ViewInvalidData from Render, never from Make.

Why

goravel/framework#1594 adds a render path that returns the rendered string instead of writing to a response, so views can be produced from console commands, queued jobs and mail without a request in scope. The example app only covered views behind http.Context, which left the string API, its data handling and its fall-through behaviour untested. tests/feature/view_render_test.go closes that gap and also covers the shared-data merge, where template data wins over Share and rendering does not write back into the shared map.

// Render a body outside a request, preferring a specific view and falling back
// to the package default when neither template is renderable.
html, err := facades.View().First([]string{
	"mail/welcome.tmpl",
	"mail/default.tmpl",
}, map[string]any{
	"name": user.Name,
}).Render()
if err != nil {
	return fmt.Errorf("render welcome mail: %w", err)
}

The framework replace is pinned to v1.18.1-0.20261027090652-c67cea858086 (c67cea85), the commit that introduces Make, First and Render, so the suite compiles against the feature while it is still unreleased; go mod tidy moved a few transitive versions with it. The define-only nav.tmpl fixture lives in the already-registered packages/viewtest/views/partials directory, which gives First a file that exists but cannot render under its own path without shipping a test-only partial in resources/views. The existing HTTP ViewTestSuite still passes against the new pin.

….Render (framework#1594)

Pin the framework replace to c67cea85 so the new render API is available,
register a define-only nav fixture in the viewtest package source, and cover
request-free rendering, data/With/Name, app-over-package precedence, First
fall-through, invalid data and shared-data merging.
@goravel-agent
goravel-agent requested a review from a team as a code owner October 27, 2026 10:18
@hwbrzzl
hwbrzzl merged commit cce32c2 into master Oct 27, 2026
9 checks passed
@hwbrzzl
hwbrzzl deleted the ship/2026-10-27-example-view-render-tests branch October 27, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants