MARY.WIN

RUSTY — INERTIA — CHAPTER 05

Testing
Pages

Chapter 5 of 10 in Inertia on Rust, draft chapters on the Inertia adapter for Rust.

Every chapter so far ended with a test, and every one of those tests used the same type. In this chapter we'll look at that type directly: how it reads a response, which assertions it offers, and the two checks it makes that are easy to miss.

This chapter assumes Chapters 1 to 4. It does not cover reloading a page or loading deferred props from a test.

Reading a page from a response

The test asserted the component name Invoices/Show and passed for a month. The file on disk was Invoice/Show.tsx. The handler agreed with the test, the test agreed with the handler, and neither had been introduced to the frontend.

Sometimes you want to assert on what a handler sent without starting a browser. Thankfully, the crate ships a type for that. Take a look at Example 5-1.

Example 5-1. Component, values and absences

AssertablePage::from_body(&reply.body)
    .component("Invoices/Show")
    .equals("invoiceId", 7)
    .equals("auth.user", "Mary")
    .missing("note");

Let's walk through it. from_body reads the page from a response body, whether that body is the JSON of an Inertia visit or the HTML document of a first visit. component checks the page's component name. equals and missing take a prop path in dot notation, so auth.user reaches inside the auth prop. Each assertion panics with a message when it fails, which is what fails the test.

Two checks that are easy to miss

You can also ask a scope to account for every key. Inside scope, the closure must assert on each key of the object or call etc() to allow the rest (see Example 5-2).

Example 5-2. A scope that tolerates nothing extra

page.scope("invoice", |invoice| invoice.equals("id", 7));

Run against a page whose invoice prop is {"id":7,"secret":"x"}, Example 5-2 panics and names secret. That is the check that notices a field you didn't mean to send.

The second check is for the file. Give the page your pages directory with pages_in, and component also asserts that a page file exists for that name, with one of six extensions: js, jsx, svelte, ts, tsx or vue (see Example 5-3).

Example 5-3. The component must exist on disk

AssertablePage::from_body(&reply.body)
    .pages_in("resources/js/Pages")
    .component("Invoices/Show");

If you're unsure where to start, I'd put pages_in in the one helper every test uses to build its page, so no test can skip it.

What this chapter leaves open

So the handler, the test and the file now agree on a name. What none of them checks is whether Show.tsx reads invoiceId or invoice_id. Chapter 1 generated a type for that. Is the type imported by the component? What fails, and when, if it isn't?

Testing

This chapter's listings are themselves tests. Examples 5-2 and 5-3 are run as tests that are expected to panic, one on the unasserted key and one on an empty pages directory.

TL;DR

AssertablePage::from_body reads a page from JSON or from a first visit's HTML. component, equals, missing, flash and missing_flash assert on it, with dot paths into props. A scope must assert on every key unless etc() is called. With pages_in, component also requires a page file on disk.

The sources.

Each line is a claim this chapter makes and where to look. Checked on 2026-11-29 against inertia-laravel-rust at commit 3ccc126.

CLAIM × WHERE — 7
  • from_body reads the JSON of an Inertia visit or the HTML document of a first visitR1 · src/testing.rs L63-L72
  • Assertions panic with a descriptive message; prop paths use dot notationR1 · src/testing.rs L37-L40
  • component, equals, missing, flash, missing_flash exist as describedR1 · src/testing.rs L142-L161, L245-L259, L440-L473
  • A scope must assert on every key or call etc()R1 · src/testing.rs L322-L341, L383-L423
  • With pages_in, component also asserts a page file exists; six extensionsR1 · src/testing.rs L59-L60, L91-L99, L150-L159
  • The path resources/js/Pages in Example 5-3Illustrative; not a claim about the crate
  • Reload and deferred-prop helpers exist and are out of scopeR1 · src/testing.rs L505-L605 (signatures only)

R1: inertiajs/inertia-laravel-rust @3ccc126a24c8fb5bddb140876a1825292c0d216c