When using Inertia, the response returned from the server is a JSON object that includes the component name and the props to be passed to the component. Therefore, the assertSee method won't work as expected because it's looking for the string in the HTML response, which is not available in this case.
To test the content of the component, you can use the assertInertia method provided by the Inertia testing helpers. This method allows you to assert that a specific component was rendered with the expected props.
Here's an example of how to use assertInertia to test the content of the Dashboard component:
public function test_only_admin_can_see_dashboard_screen(): void
{
$userClient = User::factory()->create(['role' => 'admin']);
$this->actingAs($userClient);
$response = $this->get('/dashboard');
$response->assertInertia(function (Assert $page) {
$page->component('Dashboard')
->has('message', "You're logged in!");
});
}
In this example, we're using the assertInertia method to assert that the response contains a component named Dashboard with a prop named message that has the value "You're logged in!".
Note that we're using a closure to define the assertions, which allows us to use the Assert object provided by the Inertia testing helpers to make the assertions.
Also, make sure to include the use statement for the Assert class at the top of your test file:
use Illuminate\Testing\Assert;