Skip to content

Testing lazy props #595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

JeroenGovers
Copy link

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.

@pascalbaljet
Copy link
Member

Thanks for this! I've reworked it a bit in #738 as this was targeted at 0.x. I also didn't want to rely on the app environment and binding in the container. When the new PR is merged, I'll make sure to add you as a contributor!

@JeroenGovers
Copy link
Author

Thanks for this! I've reworked it a bit in #738 as this was targeted at 0.x. I also didn't want to rely on the app environment and binding in the container. When the new PR is merged, I'll make sure to add you as a contributor!

@pascalbaljet it's great to hear that the new test helpers are now available in 2.x. I will definitely use them in my tests. You spoke of making me a contributor when the PR is merged. I would realy love that ☺️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants