`Attempt to read property "form" on null` error in test
I'm getting this error in a test:
This is the test:
CompleteRegistration is a filament page:
I don't get this error on other pages. Can anyone see what I'm doing wrong?
Attempt to read property "form" on null
at vendor/filament/forms/src/Testing/TestsForms.php:125
121▕ public function assertFormExists(): Closure
122▕ {
123▕ return function (string $name = 'form'): static {
124▕ /** @var ComponentContainer $form */
➜ 125▕ $form = $this->instance()->{$name};
Attempt to read property "form" on null
at vendor/filament/forms/src/Testing/TestsForms.php:125
121▕ public function assertFormExists(): Closure
122▕ {
123▕ return function (string $name = 'form'): static {
124▕ /** @var ComponentContainer $form */
➜ 125▕ $form = $this->instance()->{$name};
it("needs an existing account user", function () {
\Pest\Livewire\livewire(CompleteRegistration::class)
->fillForm([
'email' => '[email protected]',
])
->call('register')
->assertRedirect(filament()->getLoginUrl());
});
it("needs an existing account user", function () {
\Pest\Livewire\livewire(CompleteRegistration::class)
->fillForm([
'email' => '[email protected]',
])
->call('register')
->assertRedirect(filament()->getLoginUrl());
});
<?php
namespace App\Filament\Pages\Auth;
use DanHarrin\LivewireRateLimiting\WithRateLimiting;
use Filament\Forms\Form;
use Filament\Http\Middleware\Authenticate;
use Filament\Pages\Page;
use Livewire\Features\SupportRedirects\Redirector;
/**
* @property-read \Filament\Forms\ComponentContainer $form
*/
class CompleteRegistration extends Page
{
use WithRateLimiting;
public ?array $data = [];
protected static string $view = 'filament.auth.complete-registration';
protected static string $layout = 'filament-panels::components.layout.simple';
protected static string | array $withoutRouteMiddleware = [
Authenticate::class,
];
public function mount(): void
{
$this->form->fill([
// defaults
]);
}
public function register(): Redirector
{
// register
}
public function form(Form $form): Form
{
return $form
->statePath('data')
->schema([
// schema
]);
}
public function hasLogo(): bool
{
return true;
}
}
<?php
namespace App\Filament\Pages\Auth;
use DanHarrin\LivewireRateLimiting\WithRateLimiting;
use Filament\Forms\Form;
use Filament\Http\Middleware\Authenticate;
use Filament\Pages\Page;
use Livewire\Features\SupportRedirects\Redirector;
/**
* @property-read \Filament\Forms\ComponentContainer $form
*/
class CompleteRegistration extends Page
{
use WithRateLimiting;
public ?array $data = [];
protected static string $view = 'filament.auth.complete-registration';
protected static string $layout = 'filament-panels::components.layout.simple';
protected static string | array $withoutRouteMiddleware = [
Authenticate::class,
];
public function mount(): void
{
$this->form->fill([
// defaults
]);
}
public function register(): Redirector
{
// register
}
public function form(Form $form): Form
{
return $form
->statePath('data')
->schema([
// schema
]);
}
public function hasLogo(): bool
{
return true;
}
}
Solution:Jump to solution
Turns out it was because I had a check in the mount that triggered a redirect if the user was already registered
1 Reply
Solution
Turns out it was because I had a check in the mount that triggered a redirect if the user was already registered