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.
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:
- The problem is with my selector, or the test just search in the
bodyelement 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) - 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!
