"This test did not perform any assertions" while it does
Hey everyone, I hope you are doing well.
While I was trying to pass my test, it gave me an alert for having a "risky test" that does not perform any assertions.
My test is this:
class ProjectTaskTest extends TestCase
{
use RefreshDatabase;
public function test_a_project_can_have_tasks()
{
$this->signIn();
$project = auth()->user()->projects()->create(
Project::factory()->raw()
);
$this->post($project->path() . '/tasks', ['body' => 'Task body example']);
$this->get($project->path())->assertSee('Task body example');
}
}
I'm doing the "assertSee" assertion but I'm a bit confused about this alert.
I would highly appreciate a little bit of help! :D
You should do the post and assert that the database has the record. And then just use a factory to create a post and assert that the view has the task shown.
What about this:
$response = $this->get($project->path());
$response->assertSee('Task body example');
and even try dd('here') before the $this->get() call and check if you are getting to that line at all.
But as I said above separate the test into two separate calls:
$this->post($project->path() . '/tasks', ['body' => 'Task body example']);
$this->assertDatabaseHas('posts', ['body' => 'Task body example']);