rawnato's avatar

Laravel 6 Test After Redirect

Hello All

I have this test

/**
 * @test
 */
public function testUserCanUpdateProfileData()
{
    $this->login();
    $new = ['name' => $this->faker->name, 'email' => $this->faker->safeEmail];

    $this->post('/profile', $new)->assertRedirect('/profile')->assertSee($new['name'])->assertSee($new['email']);
}   

This test not working, do you know what happens?

0 likes
3 replies
Nakov's avatar
Nakov
Best Answer
Level 73

@rdehnhardt I never attached assertSee to a redirect, so I don't know if that should ever work. What I usually would do is the following:

$this->post('/profile', $new)
    ->assertRedirect('/profile')
    ->assertSessionHasNoErrors();

$this->get('/profile')
    ->assertOk()
    ->assertSee($new['name'])
    ->assertSee($new['email']);
1 like
Tray2's avatar

I do the same as @nakov in my tests.

        $this->delete('/books/read/' . $book->id);
        $response = $this->get('/books/' . $book->id);
        $response->assertSee(e($book->title) . ' marked as unread.');
        $this->assertEquals(0, BookRead::count());
1 like

Please or to participate in this conversation.