umairparacha's avatar

My registration test is falling

Here is my code

<?php

namespace Tests\Feature;

use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Jetstream\Jetstream;
use Tests\TestCase;

class RegistrationTest extends TestCase
{
    use RefreshDatabase;

    public function test_registration_screen_can_be_rendered()
    {
        $response = $this->get('/register');

        $response->assertStatus(200);
    }

    public function test_new_users_can_register()
    {
        $response = $this->post('/register', [
            'name' => 'Test User',
            'email' => '[email protected]',
            'user_name' => 'test_user',
            'business_name' => 'Tewst Business',
            'password' => 'password',
            'password_confirmation' => 'password',
            'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
        ]);
        $this->assertAuthenticated();
        $response->assertRedirect(RouteServiceProvider::HOME);
    }
}

and the error

  • Tests\Feature\RegistrationTest > new users can register
  The user is not authenticated
  Failed asserting that false is true.

  at D:\Laravel\laravel8\projects\pos.test\tests\Feature\RegistrationTest.php:34
     30▕             'password' => 'password',
     31▕             'password_confirmation' => 'password',
     32▕             'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
     33▕         ]);
  ➜  34▕         $this->assertAuthenticated();
     35▕         $response->assertRedirect(RouteServiceProvider::HOME);
     36▕     }
     37▕ }
     38▕

  1   D:\Laravel\laravel8\projects\pos.test\vendor\phpunit\phpunit\phpunit:61
      PHPUnit\TextUI\Command::main()


  Tests:  1 failed, 3 skipped, 27 passed
  Time:   3.71s
0 likes
2 replies
martinbean's avatar
Level 80

@umairparacha You’re not authenticated. So check the response for any validation errors.

$response->assertSessionHasNoErrors();

If the session does have any errors, then the test will fail but it will also show you which rules failed validation.

1 like

Please or to participate in this conversation.