Target class [livewire] does not exist.

I have installed the Pest Livewire plugin according to the documentation:
https://pestphp.com/docs/plugins#livewire
I set up a TestCase, configuring the default user and panel.
I created the following simple test:
<?php

use App\Filament\App\Resources\ImportResource\Pages\ListImports;

use function Pest\Livewire\livewire;

it('can render the index page', function () {
livewire(ListImports::class)
->assertSuccessful();
});
<?php

use App\Filament\App\Resources\ImportResource\Pages\ListImports;

use function Pest\Livewire\livewire;

it('can render the index page', function () {
livewire(ListImports::class)
->assertSuccessful();
});
However, I receive the following error:
FAILED Tests\Feature\Filament\Resources\ImportResourceTest > it can render the index page
BindingResolutionException
Target class [livewire] does not exist.
FAILED Tests\Feature\Filament\Resources\ImportResourceTest > it can render the index page
BindingResolutionException
Target class [livewire] does not exist.
Plugins | Pest - The elegant PHP Testing Framework
In this section, we will discuss the official and community developed plugins that we endorse. Plugins primarily offer namespaced functions, console commands, custom expectations, and additional command-line options to augment the default Pest experience.
16 Replies
LeandroFerreira
dd(app()->runningUnitTests()); what is the output? what is the error?
LeandroFerreira
dd(app()->runningUnitTests()); what is the output?
LeandroFerreira
add the dd inside the test..
Héctor Q. Torres
My bad 🤣 Ok, return 'false'
LeandroFerreira
what is the APP_ENV value from phpunit.xml file?
Héctor Q. Torres
But I have an env.testing variable set, pointing to a test database.
LeandroFerreira
are you using docker?
Héctor Q. Torres
Yes, i am
LeandroFerreira
are you running the test inside the container?
Héctor Q. Torres
Yes, I am
LeandroFerreira
I recommend double checking your env because definitely dd(app()->runningUnitTests()); should return true.. You could also try the same test in another Filament fresh install
Héctor Q. Torres
I think this will be better, thank you for your time. If I figure out the problem, I’ll come back here with the solution. I discovered the problem. Actually, I had started the project using the PHPUnit package (since I was used to using it for API tests). However, after creating a new project from scratch and choosing Pest, I noticed that a file is created: /tests/Pest.php:
<?php

pest()->extend(Tests\TestCase::class)
// ->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
->in('Feature');

expect()->extend('toBeOne', function () {
return $this->toBe(1);
});

function something()
{
// ..
}
<?php

pest()->extend(Tests\TestCase::class)
// ->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
->in('Feature');

expect()->extend('toBeOne', function () {
return $this->toBe(1);
});

function something()
{
// ..
}
This way, everything worked correctly. Since my scenario involves multi-tenancy, I also needed to add the following setup in TestCase:
Filament::setTenant(MyEntityTenant::where(...)->first())
Filament::setTenant(MyEntityTenant::where(...)->first())
Thanks for the help again!

Did you find this page helpful?