inertiajs/inertia-laravel Testing Helpers
NOTE: This package WILL be deprecated once ANY official testing helpers become available in inertiajs/inertia-laravel. The package WILL stay available for install, but WILL NOT receive any further (security) updates from that point forward.
You can install the package via composer:
composer require --dev claudiodekker/inertia-laravel-testing
To test, simply chain any of the following methods onto your TestResponse
responses.
The methods made available in this package closely reflect those available in Laravel itself:
Assert whether the given page is an Inertia-rendered view
$response->assertInertia();
// or, also check whether the page is a specific component
$response->assertInertia('example');
// or, also check whether all of the given props match
$response->assertInertia('example', [
'foo' => 'bar'
]);
Return all available Inertia props for the page, or only retrieve a specific one
$response->inertiaProps();
// Retrieve a specific (nested) prop. Returns `null` if the prop doesn't exist.
$response->inertiaProps('nested.prop');
Assert whether the Inertia-rendered view has a specific property set
$response->assertInertiaHas('key');
// or, against deeply nested values
$response->assertInertiaHas('deeply.nested.key');
Apart from checking whether the property is set, the same method can be used to assert that the values match
$response->assertInertiaHas('key', 'matches-this-value');
// or, for deeply nested values
$response->assertInertiaHas('deeply.nested.key', 'also-match-against-this-value');
It's also possible to assert directly against a Laravel Model (or any other Arrayable
or Responsable
class)
$user = UserFactory::new()->create(['name' => 'John Doe']);
// ... (Make HTTP request etc.)
$response->assertInertiaHas('user', $user);
$response->assertInertiaHas('deeply.nested.user', $user);
It's also possible to check against a closure
$response->assertInertiaHas('foo', function ($value) {
return $value === 'bar';
});
// or, again, for deeply nested values
$response->assertInertiaHas('deeply.nested.foo', function ($value) {
return $value === 'bar';
});
Next, you can also check against a whole array of properties. It'll simply loop over them using the assertInertiaHas
method described above:
$response->assertInertiaHasAll([
'foo',
'bar.baz',
'another.nested.key' => 'example-value'
]);
Finally, you can assert that a property was not set:
$response->assertInertiaMissing('key');
// or, for deeply nested values
$response->assertInertiaMissing('deeply.nested.key');
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email claudio@ubient.net instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.