smartymoon/inertia-laravel-testing

Testing helpers for https://github.com/inertiajs/inertia-laravel

dev-master 2021-05-03 01:58 UTC

This package is auto-updated.

Last update: 2024-04-29 04:39:46 UTC


README

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.

Latest Version Build Status Quality Score StyleCI Total Downloads

Installation

You can install the package via composer:

composer require --dev claudiodekker/inertia-laravel-testing

Usage

To test, simply chain any of the following methods onto your TestResponse responses.

Screenshot 2020-09-02 at 19 44 39

Available Methods

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');

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email claudio@ubient.net instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.