May 1, 2021
6
Level 20
How do you test Inertia.js?
I know there used to be an Inertia testing packing, but it has since been merged into Laravel as the new json testing helpers.
But I don't understand how I would test a simple controller method like this:
public function show(Client $client)
{
return Inertia::render('Clients/Show', [
'client' => [
'id' => $client->id,
'name' => $client->name,
'email' => $client->email,
],
]);
}
Here's what I have but I keep getting the error:
Invalid JSON was returned from the route.
/** @test */
public function show()
{
$client = Client::factory()->create([
'name' => 'Apple',
'email' => '[email protected]',
]);
$this->get(route('clients.show', $client))
->assertJson(fn (AssertableJson $json) =>
$json->has('client')
->where('name', 'Apple')
->where('email', '[email protected]')
);
}
Level 75
2 likes
Please or to participate in this conversation.