When testing against a component which is in a subdirectory of the main Livewire namespace, assertContainsLivewireComponent fails
namespace App\Http\Livewire\Components;
use Livewire\Component;
class MyComponent extends Component
{
//...
}
test:
Livewire::test(MyParentComponent::class)
->assertContainsLivewireComponent(MyComponent::class);
Error comes back:
matches PCRE pattern "/@livewire\('my-component'|<livewire\:my-component/".
The following is okay however:
Livewire::test(MyParentComponent::class)
->assertContainsLivewireComponent('components.my-component);
Tried to look at a fix. Since assertContainsLivewireComponent uses basename() to strip out the class, I used the following (possibly ugly) fix:
return function (string $componentNeedleClass) {
$componentNeedle = Str::of($componentNeedleClass)
->remove('App\Http\Livewire\\')
->explode('\\')
->map(function($item)
{
return Str::kebab($item);
})
->implode('.');
...
I wanted to provide a pull request but, while this works me, your tests fail. I guess this is down to the fact that the test components are not in App\Http\Livewire. I'm no Livewire aficionado so I wasn't sure how to resolve this! Happy to help if I can however!
When testing against a component which is in a subdirectory of the main Livewire namespace,
assertContainsLivewireComponentfailstest:
Error comes back:
The following is okay however:
Tried to look at a fix. Since
assertContainsLivewireComponentusesbasename()to strip out the class, I used the following (possibly ugly) fix:I wanted to provide a pull request but, while this works me, your tests fail. I guess this is down to the fact that the test components are not in App\Http\Livewire. I'm no Livewire aficionado so I wasn't sure how to resolve this! Happy to help if I can however!