fillForm doesn't work while trying to test a Singular Resource

Hi, I created a Singular Resource as explained here https://filamentphp.com/docs/4.x/resources/singular My view is exactly the same as in the documentation and my page's form method is a little bit different since this page is here to create a new record instead of updating an existing one. Therefore I'm using model instead of record:
/**
* Configure the form for the page.
*/
public function form(Schema $schema): Schema
{
return ContactForm::configure($schema)
->model(Contact::class)
->statePath('data');
}
/**
* Configure the form for the page.
*/
public function form(Schema $schema): Schema
{
return ContactForm::configure($schema)
->model(Contact::class)
->statePath('data');
}
Here's how i'm testing the creation process:
it('can create', function (): void {
$newData = Contact::factory()->make();

$this->actingAs($newData->user);

livewire(ContactUs::class)
->fillForm([
'subject' => $newData->subject,
'message' => $newData->message,
])
->call('create')
->assertHasNoFormErrors();

$this->assertDatabaseHas(Contact::class, [
'user_id' => $newData->user_id,
'subject' => $newData->subject,
'message' => $newData->message,
]);
});
it('can create', function (): void {
$newData = Contact::factory()->make();

$this->actingAs($newData->user);

livewire(ContactUs::class)
->fillForm([
'subject' => $newData->subject,
'message' => $newData->message,
])
->call('create')
->assertHasNoFormErrors();

$this->assertDatabaseHas(Contact::class, [
'user_id' => $newData->user_id,
'subject' => $newData->subject,
'message' => $newData->message,
]);
});
but I get this error when the fillForm method is called:
FAILED Tests\Feature\Pages\ContactUsPageTest > it can create Error
Call to a member function getDefaultTestingSchemaName() on null

at vendor/filament/forms/src/Testing/TestsForms.php:30
26▕ if ($this->instance() instanceof HasActions) {
27▕ $form ??= $this->instance()->getMountedActionSchemaName();
28▕ }
29▕
➜ 30▕ $form ??= $this->instance()->getDefaultTestingSchemaName();
31▕
32▕ /** @phpstan-ignore-next-line */
33▕ $this->assertSchemaExists($form);
34▕

+3 vendor frames
4 tests/Feature/Pages/ContactUsPageTest.php:30
FAILED Tests\Feature\Pages\ContactUsPageTest > it can create Error
Call to a member function getDefaultTestingSchemaName() on null

at vendor/filament/forms/src/Testing/TestsForms.php:30
26▕ if ($this->instance() instanceof HasActions) {
27▕ $form ??= $this->instance()->getMountedActionSchemaName();
28▕ }
29▕
➜ 30▕ $form ??= $this->instance()->getDefaultTestingSchemaName();
31▕
32▕ /** @phpstan-ignore-next-line */
33▕ $this->assertSchemaExists($form);
34▕

+3 vendor frames
4 tests/Feature/Pages/ContactUsPageTest.php:30
Solution:
are you sure that you are authorized to view the component?
Jump to solution
4 Replies
arthurpar
arthurparOP3mo ago
It looks like it's because $this->instance() is null. Could this be because I'm using a custom view? Though it's still a livewire component Thanks in advance for your help
Solution
Dan Harrin
Dan Harrin3mo ago
are you sure that you are authorized to view the component?
Dan Harrin
Dan Harrin3mo ago
if you run livewire(ContactUs::class)->assertSuccessful() does it pass without the rest of the code? usually, the instance() is null if it fails to load/render in some way
arthurpar
arthurparOP3mo ago
hey thanks a lot for you answer you were right it was a permission issue I didn't noticed because i was using a superadmin user in my browser... Thanks again 🙂

Did you find this page helpful?