phredbel's avatar

Dusk Test failing

So I have this initial test I set up for Dusk testing logging in:

use Laravel\Dusk\Browser;
use App\Models\User;
use Spatie\Permission\Contracts\Role;


beforeEach(function () {
    $this->user = User::factory()->create([
        'email'    => '[email protected]',
        'password' => Hash::make('password'),
    ]);

    $role = app(Role::class)->findOrCreate('User', 'web');

    $this->user->assignRole($role);
});

test('user login', function () {

    $this->browse(function (Browser $browser) {

        $browser->visit('/')
            ->type('email', $this->user->email)
            ->type('password', 'password')
            ->click('button[type="submit"]')
            ->assertPathIs('/dashboard');
    });
});

it always fails that this user isn't found. I have created a dusk .env file and created a separate db for dusk. When I comment out use LazilyRefreshDatabase; from my Dusk Test Case class I see that this user is being created in the db. Any help as to how to debug this would be great.

0 likes
0 replies

Please or to participate in this conversation.