claudiodekker / inertia-laravel-testing

Testing helpers for https://github.com/inertiajs/inertia-laravel
MIT License
134 stars 6 forks source link

V2 - Testing Packages #33

Open herpaderpaldent opened 3 years ago

herpaderpaldent commented 3 years ago

I encountered an issue for testing components with "claudiodekker/inertia-laravel-testing": "^2.2". We managed to resolve the issue but i will post its solution here, in order to be of assistance for others that might encounter this issue.

This package tries to verify the existence of such components within https://github.com/claudiodekker/inertia-laravel-testing/blob/8c8191b2b910ebdd4979911c9fbae60a188a85b4/src/Concerns/PageObject.php#L17.

If you are developing a laravel package you are most porbably using orchestral/testbench and therefore /vendor/orchestra/testbench-core/laravel/resources/js/Pages will be missing the component.

In order to get testing to work one must extend your TestCase.php file:

protected function getEnvironmentSetUp($app)
    {
        ...

        //Setup Inertia for package development
        config()->set('inertia.page.paths', array_merge(
            config()->get('inertia.page.paths', []),
            [realpath(__DIR__ . '/../src/resources/js/Pages')],
        ));
    }
claudiodekker commented 3 years ago

While I wouldn't mind adding a section about Package Development to the readme, since all that's really being done here is changing the configuration setting (which I'm assuming most Laravel developers already know about?) I don't think/know if it's worth to add it.

That said, I'd love to hear from others that ran into this. No need to comment explicitly (although, feel free!): Simply adding a thumbs-up to this issue would be sufficient to give me a bit of an idea as to how many people run into this issue 👍

Thanks!