Can't access tenant in Test class?

A simple test like this:
public function test_renders_successfully()
{
Livewire::test(TimeSheet::class)
->assertStatus(200);
}
public function test_renders_successfully()
{
Livewire::test(TimeSheet::class)
->assertStatus(200);
}
fails because it says it's missing the tenant parameter in the route. I've tried doing something like Filament::setTenant(Team::factory()->create()); in my setup method, and various other things and can't seem to get it to either use a fake tenant, or to ignore the tenant entirely. This particular page doesn't even rely on tenancy, it just exists in a panel where tenancy is used. Any ideas?
2 Replies
awcodes
awcodes5w ago
You need to pass the tenant id to the class. So something like
Livewire::test(Timesheet::class, [‘tenant’ => $tenant])
Livewire::test(Timesheet::class, [‘tenant’ => $tenant])
Probably need to pass the record too. Look at the testing docs for panels. That concept is the same. Just because you set the tenant doesn’t mean it’s automatically inferred in a testing context unless you are hitting an actual route so livewire needs it passed it directly.
Jon Mason
Jon Mason5w ago
ok, i'll give it a try, thanks!
Want results from more Discord servers?
Add your server