Better way for testing validation errors

I think there is more clear way to get an exact error message from session.

    /** @var ViewErrorBag $errors */
    $errors = request()->session()->get('errors');
    /** @var array $messages */
    $messages = $errors->getBag('default')->getMessages();
    $emailErrorMessage = array_shift($messages['email']);

    $this->assertEquals('Already in use', $emailErrorMessage);

Pre-requirements: code was tested on Laravel Framework 5.5.14


you can do it like so -

$this->assertSessionHas('flash_notification.level', 'danger'); if you are looking for a particular error or success key.

or use $this->assertSessionHasErrors();