inertiajs / inertia-laravel

The Laravel adapter for Inertia.js.
https://inertiajs.com
MIT License
2.01k stars 224 forks source link

Testing lazy props #595

Open JeroenGovers opened 5 months ago

JeroenGovers commented 5 months ago

I added the method requestProp (name open for discussion 😉) to the AssertableInertia class which let you easy test LazyProps.

/** @test */
public function test_props(): void
{
    $this
        ->get('/')
        ->assertInertia(function (AssertableInertia $page) {
            $page->has('normalPropKey');
            $page->missing('lazyPropKey');

            $page->requestProp('lazyPropKey', function (AssertableInertia $page) {
                $page->where('lazyPropKey', '1');
            });
        });
}

The method uses the previous request, applies the X-Inertia-Partial-Component and X-Inertia-Partial-Data headers, which are automatically seeded and resends it. A convenient way for the tester, and they do not need to know the internal mechanics of Intertia. Which I found in #604.