Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lukeboy_2002's avatar

Error in test

I have two failed test with jetstream. Instead of logging in with email I use the username. This works but in my test it's failing at profileInformationtest and Registrationtest.

profileInformationtest

test('profile information can be updated', function () {
    $this->actingAs($user = User::factory()->create());

    Livewire::test(UpdateProfileInformationForm::class)
        ->set('state', ['username' => 'Test.user', 'email' => '[email protected]'])
        ->call('updateProfileInformation');

    expect($user->fresh())
        ->username->toEqual('Test.user')
        ->email->toEqual('[email protected]');
});

Error:

Failed asserting that two strings are equal.
Expected :'Test.user'
Actual   :'dsawayn'

Registrationtest

test('new users can register', function () {
    $response = $this->post('/register', [
        'name' => 'Test User',
        'username' => 'Tester',
        'email' => '[email protected]',
        'password' => 'password',
        'password_confirmation' => 'password',
        'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
    ]);

    $this->assertAuthenticated();
    $response->assertRedirect(route('dashboard', absolute: false));
})->skip(function () {
    return ! Features::enabled(Features::registration());
}, 'Registration support is not enabled.');

error:

The user is not authenticated
Failed asserting that false is true.
at vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithAuthentication.php:49
at tests/Feature/RegistrationTest.php:32

line 32: $this->assertAuthenticated();

my model:

My factory

    public function definition(): array
    {
        return [
            'username' => fake()->unique()->userName(),
            'name' => fake()->name(),
            'email' => fake()->unique()->safeEmail(),
            'email_verified_at' => now(),
            'password' => static::$password ??= Hash::make('password'),
            'two_factor_secret' => null,
            'two_factor_recovery_codes' => null,
            'remember_token' => Str::random(10),
            'profile_photo_path' => null,
            'current_team_id' => null,
        ];
    }

CreateNewUser

UpdateUserProfileInformation

What is wrong, can anybody help me.

0 likes
1 reply
LaryAI's avatar

Certainly! Let's break down both issues and provide solutions.


1. Profile Information Test Failing

Error:

Failed asserting that two strings are equal.
Expected :'Test.user'
Actual   :'dsawayn'

Cause:
You're updating the user's profile with a new username and email, but your test is asserting the changes on the original $user instance, not the updated one.
Also, your set('state', ...) is missing the name field, which is required by your validation.

Solution:

  • Add the name field when updating.
  • After calling updateProfileInformation, refresh the user from the database.

Corrected Test:

test('profile information can be updated', function () {
    $this->actingAs($user = User::factory()->create());

    Livewire::test(UpdateProfileInformationForm::class)
        ->set('state', [
            'username' => 'Test.user',
            'name' => 'Test User',
            'email' => '[email protected]',
        ])
        ->call('updateProfileInformation');

    $user->refresh();

    expect($user)
        ->username->toEqual('Test.user')
        ->email->toEqual('[email protected]');
});

2. Registration Test Failing

Error:

The user is not authenticated
Failed asserting that false is true.

Cause:
Jetstream's registration expects a name, username, email, and password.
However, you may have modified the registration form, but the backend (CreateNewUser) expects all these fields.
Also, make sure your registration form and validation are in sync.

Possible Issues:

  • The registration POST request might be missing required fields (name, username).
  • The CreateNewUser action does not return the created user, which is required for authentication.

Solution:

  1. Return the user from CreateNewUser:

In your CreateNewUser action, add a return $user; at the end of the create method:

public function create(array $input): User
{
    // ... validation and user creation

    // Add role User
    $role = Role::select('id')->where('name', 'user')->first();
    $user->roles()->attach($role);

    return $user; // <--- Add this line
}
  1. Ensure your test sends all required fields:

Your test already sends name, username, email, password, and terms.
Just make sure your registration form and validation match.

If you still have issues, check:

  • The registration route is correct (/register).
  • The terms field is handled properly (try 'terms' => true if needed).

Summary

  • Profile update test: Add the name field and use $user->refresh() before assertions.
  • Registration test: Return the user from CreateNewUser::create().

Let me know if you need more help!

Please or to participate in this conversation.