getting error .
error
InvalidArgumentException: Unable to locate factory for [App\Models\User].
running this test i get the error
public function test_a_project_requires_a_title()
{
$user = factory(User::class)->create();
$this->actingAs($user);
$this->withoutExceptionHandling();
$attributes = Project::factory()->raw(['title' => '']);
$this->post('/projects', $attributes)->assertSessionHasErrors('title');
}
Have you created a factory ? Have you declared it in your test file ?
@vincent15000 yea , here it is usersFactory
public function definition()
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => 'yIXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
];
}
and how to declare it in a test file?
@vincent15000 now its telling me that , title field is required
public function test_a_project_requires_a_title()
{
$user = User::factory()->create();
$this->actingAs($user);
// parent::setUp();
$this->withoutExceptionHandling();
$attributes = Project::factory()->raw(['title' => '']);
$this->post('/projects', $attributes)->assertSessionHasErrors('title');
}
@Shivamyadav That's because your title field is required and you don't give any title.
Please or to participate in this conversation.