I personally use assertInvalid to check for validation errors
For your use case that should work like this:
followingRedirects()
->patch(route('my_details.update'), ['last_name' => 'Doe'])
->assertInvalid(['first_name']);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a similar set up to the post here: https://laracasts.com/discuss/channels/inertia/testing-inertia-with-validation
In that I'm simply trying to test validation errors with Inertia and Laravel. My controller method looks like so;
public function update(UpdateDetailsRequest $request): RedirectResponse
{
$data = $request->validated();
return Redirect::route('my_details.show')->with('message', 'Details successfully updated.');
}
And my Form Request
class UpdateDetailsRequest extends FormRequest
{
public function rules(): array
{
return [
'first_name' => ['required', 'string'],
'last_name' => ['required', 'string'],
// ...
];
}
}
And my pest unit test
test('test validation fails', function () {
followingRedirects()
->patch(route('my_details.update'), ['last_name' => 'Doe'])
->assertInertia(
function (AssertableInertia $page) {
dd($page);
return $page->component('MyDetails')
->has('errors.first_name');
}
);
});
I've tested using dd() above to print out the values as I get the failure Property [errors.first_name] does not exist. when running the test normally, and the dd confirms the error bag is empty.
-props: array:8 [
"errors" => []
//...
If I do this in the browser and inspect using Vue Dev tools I can see the error bag populating correctly when I submit my form, and every example of a test like this I've seen seems to follow this structure so I don't know why mine is not working.
I'm using Inertias useForm() helper to handle form submission on the front end.
const form = useForm({
first_name: details.first_name,
last_name: details.last_name,
});
const form_submit = (form, route) => {
form.patch(route, { /**/ });
}
<form @submit.prevent="form_submit(form, route('my_details.update'))">
Anything obvious I'm missing here?
I personally use assertInvalid to check for validation errors
For your use case that should work like this:
followingRedirects()
->patch(route('my_details.update'), ['last_name' => 'Doe'])
->assertInvalid(['first_name']);
Please or to participate in this conversation.