testbench-core icon indicating copy to clipboard operation
testbench-core copied to clipboard

Trait to test Inertia Controller

Open snake-py opened this issue 2 years ago • 2 comments

As we spoke here I created a trait to test a controller, which response with inertia response. To use this you need to do the following:

  1. Create a new file named app.blade.php in your package's resources/views directory.
  2. Call the load function from the trait

class FooTest  extends BaseTest
{
    use WithInertia;

    protected $inertiaMiddleware = HandleInertiaRequests::class;
}

You can customize the Finder using:

use Illuminate\View\FileViewFinder;

class FooTest  extends BaseTest
{
    use WithInertia;

    protected $inertiaMiddleware = HandleInertiaRequests::class;

    public function defineEnvironment($app): void
    {
        $this->defineInertia(function (FileViewFinder $finder) {
            $finder->addNamespace('WD', __DIR__.'/../../UI/resources/app/Pages');
        });
    }
}

To define custom paths or register view location.

$this->defineInertiaPages(view: 'resources/views', paths: ['resources/js/Pages']);

snake-py avatar Mar 24 '23 12:03 snake-py

Coverage Status

Coverage: 82.913% (-0.6%) from 83.537% when pulling f3d1183e5fa71507499591d1fa67a97d060e4c95 on snake-py:8.x into 2e4b270fb01cec9219a17944513804175faba27f on orchestral:8.x.

coveralls avatar Mar 27 '23 23:03 coveralls

@crynobone I am unsure if I can assist here in any way. I see that you split up the code. SHould I try to tackle this or do you want to do it?

snake-py avatar Apr 13 '23 17:04 snake-py