Im using a fresh instalation of laravel Jetstream with Teams and Livewire. Everything was working as expected but when I am trying to do some tests with livewire I get this error
1) Tests\Feature\ContactFormTest::contact_form_page_contains_contact_form_livewire
ErrorException: Trying to get property 'id' of non-object (View: /var/www/livewire/resources/views/navigation-dropdown.blade.php) (View: /var/www/livewire/resources/views/navigation-dropdown.blade.php) (View: /var/www/livewire/resources/views/navigation-dropdown.blade.php)
/var/www/livewire/vendor/laravel/jetstream/src/HasTeams.php:28
/var/www/livewire/vendor/livewire/livewire/src/CompilerEngine.php:38
/var/www/livewire/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php:60
/var/www/livewire/vendor/livewire/livewire/src/LivewireViewCompilerEngine.php:32
/var/www/livewire/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php:61
/var/www/livewire/vendor/laravel/framework/src/Illuminate/View/View.php:139
/var/www/livewire/vendor/laravel/framework/src/Illuminate/View/View.php:122
/var/www/livewire/vendor/laravel/framework/src/Illuminate/View/View.php:91
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Http/Response.php:62
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Http/Response.php:34
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Routing/Router.php:765
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Routing/Router.php:737
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Routing/Router.php:691
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:128
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Auth/Middleware/EnsureEmailIsVerified.php:29
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:41
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php:44
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:77
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167
/var/www/livewire/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Session/Middleware/AuthenticateSession.php:58
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:116
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:62
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:67
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:103
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Routing/Router.php:693
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Routing/Router.php:668
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Routing/Router.php:634
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Routing/Router.php:623
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:166
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:128
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php:87
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167
/var/www/livewire/vendor/fruitcake/laravel-cors/src/HandleCors.php:37
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167
/var/www/livewire/vendor/fideloper/proxy/src/TrustProxies.php:57
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:167
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:103
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:141
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:110
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:508
/var/www/livewire/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:292
/var/www/livewire/tests/Feature/ContactFormTest.php:20
Looks like thats something related with teams. Does anyone knows how to workaround this issue? thanks in advance
I just had this problem a while ago. This is caused because factory Users doesn't have a personal team created.
You can force the personal team creation using the same code inside the fortify action:
Then your tests should look like this:
And to avoid using this gigantic block of code in every authentication you can create a helper function signIn() inside
Something like:
Then you can use in your tests