Have you ever encountered the dreaded “Not a valid Inertia response” error while testing Inertia in your Laravel app? 🤔 Something’s happening in the meantime that is throwing an exception, but we’re not able to see that exception, all what we get is a broad message of “Not a valid Inertia response”
Without ExceptionHandling to rescue
Adding the following line at the top of your test can make a world of difference
$this->withoutExceptionHandling();
This disables Laravel’s exception handling during the test, making sure Laravel isn’t going to get in the way during the test allowing you to see the raw error and its stack trace.
Example
Let’s look at a brief example to illustrate this, Let’s say you’re testing a dashboard interaction:
public function test_user_can_access_dashboard()
{
$response = $this->actingAs(User::factory()->create())
->get('/dashboard');
$response->assertStatus(200);
}
If this test fails with “Not a valid Inertia response,” you can debug it by updating the test like this:
public function test_user_can_access_dashboard()
{
$this->withoutExceptionHandling();
$response = $this->actingAs(User::factory()->create())
->get('/dashboard');
$response->assertStatus(200);
}
Now, instead of a vague Inertia error, Laravel will reveal the actual issue—whether it’s a route problem, a missing view, or an authorization failure.