Laravel(10) Dusk Login Test Failing

  Kiến thức lập trình

I have a fresh install of Dusk and I am trying to build a Login test. Here’s where I started:

use LaravelDuskBrowser;
use AppModelsUser;
use SpatiePermissionContractsRole;


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 and checking my Authenticate Controller, it’s has the correct credentials. Any help as to how to debug this would be great.

New contributor

Frederick Wells is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT