© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
2 replies
Harry

Trying to Test Password Change Functionality

Hi all - I would love some help figuring out how to write a pest test to test and simulate the flow of a user updating their password after forgetting. Here is the test I have so far, but it's always failling at the assertion of the hash result at the end (suggesting that the password change is not actually being saved to the database). I appreciate any help available. Code is below:

test('password can be reset with valid token', function () {
    Notification::fake();

    $user = User::factory()->create();
    $user->save();

    $response = $this
        ->get(route('filament.app.auth.password-reset.request'));

    $response->assertStatus(200);

    // Assert we see the email field
    $response->assertSee([
        'input',
        'id="data.email"'
    ], false);

    Livewire::test(RequestPasswordReset::class)
        ->set('data.email', $user->email)
        ->call('request')
        ->assertHasNoErrors();

    Notification::assertSentTo($user, ResetPasswordNotification::class, function ($notification) use ($user) {
        // Now that we've requested a password reset, we can test the reset password screen with the token received

        $this->assertNotNull($notification->token);

        $this->get($notification->url)
            ->assertStatus(200);

        $newPassword = 'new-password-x';

        Livewire::test(ResetPassword::class)
            ->set('password', $newPassword)
            ->set('passwordConfirmation', $newPassword)
            ->call('resetPassword')
            ->assertHasNoErrors();

        $hashResult = Hash::check($newPassword, $user->refresh()->password);

        // Assert that the password has been updated
        $this->assertTrue($hashResult);

        return true;
    });

});
test('password can be reset with valid token', function () {
    Notification::fake();

    $user = User::factory()->create();
    $user->save();

    $response = $this
        ->get(route('filament.app.auth.password-reset.request'));

    $response->assertStatus(200);

    // Assert we see the email field
    $response->assertSee([
        'input',
        'id="data.email"'
    ], false);

    Livewire::test(RequestPasswordReset::class)
        ->set('data.email', $user->email)
        ->call('request')
        ->assertHasNoErrors();

    Notification::assertSentTo($user, ResetPasswordNotification::class, function ($notification) use ($user) {
        // Now that we've requested a password reset, we can test the reset password screen with the token received

        $this->assertNotNull($notification->token);

        $this->get($notification->url)
            ->assertStatus(200);

        $newPassword = 'new-password-x';

        Livewire::test(ResetPassword::class)
            ->set('password', $newPassword)
            ->set('passwordConfirmation', $newPassword)
            ->call('resetPassword')
            ->assertHasNoErrors();

        $hashResult = Hash::check($newPassword, $user->refresh()->password);

        // Assert that the password has been updated
        $this->assertTrue($hashResult);

        return true;
    });

});
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

How to test a simple resource CRUD functionality?
FilamentFFilament / ❓┊help
3y ago
Try to change password name in LOGIN 😔
FilamentFFilament / ❓┊help
2y ago
How to change a column in users table after reseting password ? (like last_change_password) ?
FilamentFFilament / ❓┊help
11mo ago
Password reset request notification test failing
FilamentFFilament / ❓┊help
12mo ago