Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

topvillas's avatar

Testing Inertia

Who can help me out here?

I'm trying to test some (not Breeze or Fortify) authentication routes, while using Inertia.

The following (PEST) test tells me that that "Invalid JSON was returned from the route."

A quick look at Dev Tools in Chrome reveals the JSON is fine though. Any idea what's going wrong here?

it('returns a failed boolean if authentication fails', function () {
    $this->followingRedirects()
        ->post('/login', [
            'email' => '[email protected]',
            'password' => 'password'
        ])->assertJsonFragment(['failed' => true]);
});

I've had a look at Inertia Laravel Testing Helpers docs but it looks a bit crazy and over-the-top for me (at the moment).

0 likes
1 reply
topvillas's avatar
topvillas
OP
Best Answer
Level 46

If anybody else if having the same sort of problem. I solved it by using assertSee rather than trying to examine the JSON (which doesn't really exist). As a quick dd of the response content revealed.

assertSee('"failed":true', true)

Please or to participate in this conversation.