Livewire Make Command can now Scaffold a Component Test


February 24th, 2021


Livewire v2.4.0 was just released with added support for a --test option when running the php artisan livewire:make command.

The new --test option, when included, will scaffold a test class for the component in the tests/Features/Livewire directory similar to the php artisan make:test command.

php artisan livewire:make ExampleComponent --test


namespace Tests\Feature\Livewire;

use App\Http\Livewire\ExampleComponent;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Livewire\Livewire;
use Tests\TestCase;

class ExampleComponentTest extends TestCase
    /** @test */
    public function the_component_can_render()
        $component = Livewire::test(ExampleComponent::class);


I've been working on several Livewire projects lately and creating new components every day, so I had the idea to create this option in order to save me (and other Livewire users) time. Instead of having to create a new component, then manually creating a test class, just add the --test option and start writing your tests!

Filed in:

Jason Beggs

TALL stack (Tailwind CSS, Alpine.js, Laravel, and Livewire) consultant and owner of