Skip to content

fix: livewire finder resolution for contained component assertions#47

Merged
christophrumpel merged 2 commits into
christophrumpel:productionfrom
Ing-LuisGuerrero:fix/livewire-finder-namespace
Mar 29, 2026
Merged

fix: livewire finder resolution for contained component assertions#47
christophrumpel merged 2 commits into
christophrumpel:productionfrom
Ing-LuisGuerrero:fix/livewire-finder-namespace

Conversation

@Ing-LuisGuerrero

@Ing-LuisGuerrero Ing-LuisGuerrero commented Mar 28, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes namespaced component resolution in both assertContainsLivewireComponent() and assertDoesNotContainLivewireComponent() when Livewire components are resolved through a configured class namespace such as App\Livewire.

In Livewire 4, the finder is not just a plain helper class. Livewire registers a configured finder singleton in the container as livewire.finder, and during registration it adds the component class namespace from config('livewire.class_namespace') as well as any additional component namespaces. Livewire then uses that configured finder to normalize component class names into the component names used in Blade tags and directives.

These assertions were resolving class-based components with a fresh Finder instance via app(Finder::class). That creates a new finder instead of reusing Livewire's configured singleton. Because that fresh instance does not know about the namespaces registered by Livewire, normalizeName() can return the wrong component name. For example, a component under the default App\Livewire namespace may be normalized as app.livewire.component.index instead of component.index.

Changes

  • use the container-bound Livewire finder via app('livewire.finder') in assertContainsLivewireComponent()
  • use the same configured finder in assertDoesNotContainLivewireComponent()
  • add regression coverage for both positive and negative assertions with livewire.class_namespace set to a configured namespace
  • add a minimal fixture component and view to reproduce the namespaced resolution case

Why this matters

These assertions are expected to follow the same component resolution rules as Livewire itself. Reusing livewire.finder is important because it carries the namespace configuration that Livewire registers at boot time. Without that, tests can fail or behave inconsistently even though the component usage is valid in a real application.

This change keeps the package aligned with Livewire 3 behavior, avoids false positives and false negatives, and improves compatibility for applications using the default namespace or custom component namespaces.

Testing

Ran:

./vendor/bin/pest tests/AssertionsTest.php

Notes

This is a focused bug fix with regression coverage and no intended public API change.

References

@Ing-LuisGuerrero Ing-LuisGuerrero marked this pull request as ready for review March 28, 2026 06:07
@christophrumpel christophrumpel merged commit 328dada into christophrumpel:production Mar 29, 2026
0 of 30 checks passed
@christophrumpel

Copy link
Copy Markdown
Owner

thanks 🙏

@Ing-LuisGuerrero Ing-LuisGuerrero deleted the fix/livewire-finder-namespace branch March 30, 2026 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants