It seems like you're trying to use Pest's syntax to write Dusk tests, which is not directly supported out of the box. Pest is a testing framework that is built on top of PHPUnit, and while it provides a more expressive syntax for writing tests, it doesn't automatically work with Laravel Dusk without some additional setup.
However, you can integrate Pest with Dusk by creating a helper function that allows you to use Pest's syntax for Dusk tests. Here's how you can do it:
First, create a helper function in a Pest test file or a dedicated helper file that you include in your Pest tests. This function will be responsible for creating a DuskTestCase instance and running the browser test:
// tests/PestDusk.php
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
function dusk(Closure $callback)
{
$test = new class extends DuskTestCase {
public function test(Closure $callback)
{
$this->browse($callback);
}
};
test()->test($callback);
}
Now, you can use this dusk function in your Pest tests like so:
// tests/Browser/exampleTest.php
use Laravel\Dusk\Browser;
it('displays the correct welcome message', function () {
dusk(function (Browser $browser) {
$browser->visit('/')
->assertSee('Laravel');
});
});
Make sure to include the helper file in your Pest tests if it's not in the same file:
// tests/Pest.php
require_once 'PestDusk.php';
Now, when you run sail pest, it should correctly execute your Dusk tests using Pest's syntax.
Keep in mind that this is a workaround to use Pest's syntax with Dusk, and it may not support all features of Pest or Dusk. If you encounter any issues, you may need to adjust the helper function or revert to using the standard PHPUnit syntax for Dusk tests.