Filament testing breaks down as soon as i use a policy

So let's say i have a simple test:
it('can delete', function () {
$dataset = Dataset::factory()->create();

livewire(DatasetResource\Pages\EditDataset::class, [
'record' => $dataset->getRouteKey(),
])
->callAction(DeleteAction::class);

$this->assertModelMissing($dataset);
});
it('can delete', function () {
$dataset = Dataset::factory()->create();

livewire(DatasetResource\Pages\EditDataset::class, [
'record' => $dataset->getRouteKey(),
])
->callAction(DeleteAction::class);

$this->assertModelMissing($dataset);
});
THis works fine if there is no dataset policy, as soon as there is one i get this error: FAILED Tests\Feature\DatasetTest > it can delete Error
Call to a member function getAction() on null at vendor/filament/actions/src/Testing/TestsActions.php:141 137▕ / @var array<string> $name */ 138▕ / @phpstan-ignore-next-line */ 139▕ $name = $this->parseNestedActionName($name); 140▕ ➜ 141▕ $action = $this->instance()->getAction($name); 142▕ 143▕ $livewireClass = $this->instance()::class; 144▕ $prettyName = implode(' > ', $name); 145▕ +9 vendor frames 10 tests/Feature/DatasetTest.php:84 The policy returns true for all functions.. does anybody have a clue what's going on?
6 Replies
DanielvdSpoel
DanielvdSpoelOP14mo ago
bump
Dennis Koch
Dennis Koch14mo ago
You don’t have a logged in user, right?
Dan Harrin
Dan Harrin14mo ago
correct, the livewire component wont mount as it is not authorised to
DanielvdSpoel
DanielvdSpoelOP14mo ago
Ohhhh Your right interesting then i propably also know the fix i have this in my test case:
public function asUser(): TestCase
{
$this->seed(ShieldSeeder::class);
$user = User::factory()->create();

$user->assignRole('super_admin');

return test()->actingAs($user);
}
}
public function asUser(): TestCase
{
$this->seed(ShieldSeeder::class);
$user = User::factory()->create();

$user->assignRole('super_admin');

return test()->actingAs($user);
}
}
so i can use that in http calls like so:
$this->asUser()->get('/')
->assertStatus(200);
$this->asUser()->get('/')
->assertStatus(200);
so i have to figure out how to use that in the livewire tests also
Dan Harrin
Dan Harrin14mo ago
its the same actingAs() you dont need to chain it just call it somewhere before in the test
DanielvdSpoel
DanielvdSpoelOP14mo ago
ahh okay thanks!
Want results from more Discord servers?
Add your server