FilamentF
Filament2y ago
pace

Trying to test a form but error: Attempt to read property "form" on null

I am following the docs and i tried to test a form with this code ( PHPUnit ):


use App\Filament\Resources\UserResource\Pages\CreateUser; use Livewire\Livewire; public function test_if_valid_user_can_create_user(): void { $newData = User::factory()->make(); Livewire::test(CreateUser::class) ->fillForm([ 'name' => $newData->name, 'email' => $newData->email, 'password' => 'password', 'password_confirmation' => 'password', ]) ->call('create') ->assertHasNoErrors(); }

But it is returning the error: Attempt to read property "form" on null.

Is this livewire/livewire import right?
Solution
I forgot to authenticate the user before access the form.

$user = User::factory()->create();

// because i am using spatie package
$user->assignRole('super_admin');

$this->actingAs($user);
Was this page helpful?