It seems like the issue is that the user record is not persisting in the database when the test is running. To resolve this, you can use the create method from the DatabaseTransactions trait provided by Laravel Dusk.
Here's an updated version of the test method that includes the DatabaseTransactions trait:
use Illuminate\Foundation\Testing\DatabaseTransactions;
public function testLogin(): void
{
$this->browse(function (Browser $browser) {
$user = User::factory()->create([
'email' => '[email protected]',
]);
$browser->visit(new Login)
->type('input[name=login_key]', $user->email)
->press('input[type=submit]')
->assertSee('You have been sent an email');
});
}
By using the DatabaseTransactions trait, the test will wrap the entire test method in a database transaction. This means that any changes made to the database during the test will be rolled back after the test completes, ensuring a clean state for each test.
Make sure to include the use Illuminate\Foundation\Testing\DatabaseTransactions; statement at the top of your test file.
Let me know if this helps!