Inertia.js test frontend with Laravel Dusk

101 Views Asked by At

I am creating a Laravel project for learning purpose, so I am very beginner in Dusk, and also in writing tests. So far what I do is create a color theme toggle button. The toggle button functions well, but I want to write a test for it. My test is very simple, I just assert that the button appers on the page.

As you can see on dashboard the toggle button is appeared

My test:

public function testExample(): void
{
    $this->browse(function (Browser $browser) {
      
        $browser->visit('/dashboard')
            ->assertVisible('button[id="theme-toggle"]');


    });
}

As you can see the button appers, but the test returns false, and If I use the $browser->dump() it dumps an empty page

"<html><head></head><body></body></html>" // vendor/laravel/dusk/src/Browser.php:700"

If I put a button with the named ID in the body the test will return true. I have 2 idea what is the problem:

  1. The problem is with my selector, or the test just search in the body element and don't search in the nested div's. (With this selector I can apply style on the button, so I think the selector is just fine)
  2. The test run's before the react render out the page, and that why the test just see an empty page (I am beginner also in React!)

Any help would appreciate!

0

There are 0 best solutions below