vincent15000's avatar

BadMethodCallException: Method Illuminate\Http\Response::assertSeeLivewire does not exist.

Hello,

With Livewire 3.4.

When I run this test.

<?php
namespace Tests\Feature\Livewire\Pages;

use App\Livewire\Pages\CategoriesPage;
use App\Models\Category;
use App\Models\User;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Livewire\Livewire;
use Tests\TestCase;

class CategoriesTest extends TestCase
{
    use RefreshDatabase;

    public $user;
    public $admin;

    public function setUp(): void
    {
        parent::setUp();

        $this->user = User::factory()->create();
        $this->admin = User::factory()->admin()->create();
    }

    /** @test */
    public function categories_page_component_loads(): void
    {
        Livewire::
            test(CategoriesPage::class)
            ->assertStatus(200);
    }

    /** @test */
    public function admin_can_see_the_categories_page_component(): void
    {
        $this
            ->actingAs($this->admin)
            ->get('admin/categories')
            ->assertSeeLivewire(CategoriesPage::class);
    }
}

I get this error.

BadMethodCallException: Method Illuminate\Http\Response::assertSeeLivewire does not exist.

According to the documentation, it should work.

https://livewire.laravel.com/docs/testing#testing-a-page-contains-a-component

Is it a bug ? Perhaps I'm doing something wrong ?

Thanks for your help.

V

0 likes
5 replies
kiwi0134's avatar

This should indeed work. What versions of Laravel and Livewire are you using?

1 like
wturrell's avatar

@kiwi0134 @vincent15000 have the exact same problem with a basic smoke test (Laravel 10.43.0, Livewire 3.4.4).

Did see a suggestion elsewhere about manually adding the @livewireScripts tag in of the 'app' blade template (with a conditional to restrict to the testing environment only) but that didn't help.

1 like
AlexandruC's avatar

i have the same problem - did anybody found a workaround?

1 like

Please or to participate in this conversation.