All jobs

Write Feature Tests for an Inertia.js App

Yes. An agent writes PHPUnit feature tests that assert each Inertia page's component, props, shared data and flash messages, runs them and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

An Inertia response is a page name plus a bag of props, and a test that stops at a 200 checks neither. The agent starts by listing every page the server can render. In a Laravel app laid out like laravel/react-starter-kit, composer.json requires inertiajs/inertia-laravel ^3.0 and phpunit/phpunit ^12.5.23. routes/web.php declares welcome and dashboard with Route::inertia, routes/settings.php adds settings/appearance the same way and sends settings/profile and settings/security through ProfileController::edit and SecurityController::edit, and app/Providers/FortifyServiceProvider.php registers seven more under auth/ with Inertia::render. The agent then searches tests/ for assertInertia and finds four calls in three files: SecurityTest.php, TwoFactorChallengeTest.php and PasswordConfirmationTest.php. Every other screen test, from DashboardTest to test_login_screen_can_be_rendered, ends at assertOk().

It writes the missing assertions page by page with Inertia\Testing\AssertableInertia, which the existing tests already import as Assert. For settings/profile the test asserts component('settings/profile') and that mustVerifyEmail is true, because User implements MustVerifyEmail. For auth/login it asserts canResetPassword and that status carries a flashed session value after a password reset. For auth/reset-password it asserts the email, the token taken from the route and a non-empty passwordRules string. config/inertia.php sets testing.ensure_pages_exist to true and points pages.paths at resources/js/pages, so each component() assertion also fails when the named .tsx file is missing. A page renamed on one side only is caught by the PHP suite, with no browser involved.

Shared data gets its own test class, because every page receives it. HandleInertiaRequests::share returns name, auth.user and sidebarOpen. auth.user is $request->user(), the whole Eloquent model, so the only thing between a browser and the password hash is the #[Hidden] attribute on app/Models/User.php. The agent writes a test that visits the dashboard as a factory user and asserts auth.user.email is present while auth.user.password, auth.user.two_factor_secret, auth.user.two_factor_recovery_codes and auth.user.remember_token are missing. A second test sends sidebar_state as false with withUnencryptedCookie, since bootstrap/app.php excludes that cookie from encryption, and asserts sidebarOpen is false. A guest visit to / asserts auth.user is null.

Writes are covered through what they flash. ProfileController::update and SecurityController::update call Inertia::flash('toast', ...) with a type and a message, and resources/js/hooks/use-flash-toast.ts turns that into a Sonner toast, yet no existing test reads it. The agent opens vendor/inertiajs/inertia-laravel/src/Testing to see which flash assertions version 3 provides, follows the redirect to the page, and asserts the toast's type and message there. It adds the validation cases the kit skips: a profile update with another user's email expects a session error on email from the Rule::unique in ProfileValidationRules, and a name longer than 255 characters expects one on name. Then it runs composer test, which chains pint --parallel --test, phpstan analyse and php artisan test, and fixes what Pint or Larastan reports in the new files before it opens the pull request.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Write the missing feature tests for this Laravel and Inertia app. Read composer.json, phpunit.xml, config/inertia.php, bootstrap/app.php, routes/web.php, routes/settings.php, app/Http/Middleware/HandleInertiaRequests.php, app/Providers/FortifyServiceProvider.php, the controllers under app/Http/Controllers/Settings, app/Models/User.php and every file under tests first. List each Inertia page the server renders and which existing test asserts its component or props with assertInertia. For every page that is only checked with assertOk, add assertions on the component name and on each prop the controller or Fortify view passes. Add a test class for the shared props from HandleInertiaRequests: auth.user must not expose password, two_factor_secret, two_factor_recovery_codes or remember_token, sidebarOpen must follow the sidebar_state cookie, and a guest gets a null auth.user. Read the flash testing helpers in vendor/inertiajs/inertia-laravel before using them, then assert the toast that the profile and password updates flash. Add validation tests for a duplicate email and an over-long name on the profile update. Keep the existing skipUnlessFortifyHas guards and the chisel comment markers intact. Run composer test and fix Pint and PHPStan findings in the files you add. Do not change application code; if a test shows a real defect, leave it failing, mark nothing as skipped, and describe it. Open a pull request that lists each page, the props now asserted and the test output.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

The pull request changes files under tests/Feature only: new assertions inside the existing screen tests, a new class for shared props, and new cases in ProfileUpdateTest.php and SecurityTest.php for the flashed toast and the validation errors. Its description holds a table with one row per Inertia page, the props the server sends for it and the test that now asserts them, followed by the output of composer test, so the Pint, PHPStan and PHPUnit results are all visible without opening the run.

A reviewer checks three things before merging. First, that prop assertions describe the contract and not an accident: asserting passwordRules is a non-empty string survives a change to the password policy, asserting its exact text does not. Second, that the hidden-attribute test names every sensitive column the users table has today, since a column added later is only protected if someone adds it to both #[Hidden] and the test. Third, that no test was weakened to pass. The request tells the agent to leave a failing test in place and explain it, so a red check on the pull request is a finding about the app to read, with the failing assertion quoted in the description.

Run it on every pull request that touches a controller or a page

Create an automation on the Project with a github trigger on pull_request.opened and pull_request.synchronize and a prompt that asks for the same check on the diff: for every Inertia::render, Route::inertia or shared prop the pull request adds or changes, is there a feature test that asserts the component and the prop. Mark the automation read only and it comments with the gaps instead of pushing. The trigger adds the event after the prompt and fills in no placeholder, so the prompt has to say to read the pull request named in the event.

For a suite that should grow without anyone asking, a schedule trigger with cron set to a night-time hour starts a writing run that opens one pull request with the tests for whatever pages gained props since the last one. The automation's max_runs_per_hour caps how many runs a burst of pushes can start.

The use case this job follows, with its automation and trigger: Write the missing tests.

Why run it on Rush?

The work is mostly cross-referencing: a route file, a middleware, a provider, two controllers and a dozen .tsx files have to agree, and the only way to know a new assertion is right is to run it. On Rush the agent gets its own sandbox, installs PHP and Composer there if the image lacks them, runs composer setup and then the real composer test against the in-memory SQLite database phpunit.xml configures. Each command and its output is kept in the run's transcript, so a reviewer can see that a test failed before the assertion was corrected and passed after.

It also runs away from a developer's machine and branch. Nothing is installed locally, the working tree of whoever asked is untouched, and several repositories can get the same pass at once, each in its own sandbox and each ending in its own pull request with the suite's output attached.

Frequently asked questions

Does it need a browser or a built frontend to test Inertia pages?

No. assertInertia reads the page object the server would send, so the tests run under php artisan test like any other feature test. The one link to the frontend is ensure_pages_exist in config/inertia.php, which checks that the component file exists under resources/js/pages; it reads the filesystem and does not compile anything.

Will it use Pest or PHPUnit?

Whatever the repository already uses. The starter kit's composer.json lists PHPUnit and its tests are classes extending Tests\TestCase, so the agent writes PHPUnit methods in the same style. In a repository whose tests are Pest closures it writes Pest, and the request can say so explicitly.

What about pages behind optional Fortify features?

The kit guards those tests with skipUnlessFortifyHas, defined in tests/TestCase.php, so a project that removed registration or two-factor authentication still has a green suite. The agent keeps that guard on every test it adds for a feature page, and leaves the @chisel comment markers around feature-specific lines so the installer can still strip them.

Does it change my controllers to make tests pass?

No. The request limits the change to tests/ and says to leave a failing test in place when it exposes a real defect. If a sensitive attribute did reach auth.user, the pull request would arrive with that test red and a description naming the attribute, and the fix is a separate decision.

More Inertia.js jobs

More jobs like this: Write the missing tests

Keep reading