Using Laravel 8, I'm running some unit tests, but getting this error on one of my tests:
Call to undefined method Tests\Unit\ApplicationTest::assertSessionHasErrors()
use Tests\TestCase;
class ApplicationTest extends TestCase {
...
$applicationRef = Application::inRandomOrder()->pluck('reference')->first();
$this->post(
'http://website.test/applications/'.$applicationRef.'/update',
['title' => null]
);
$this->assertSessionHasErrors('title');
}
I've tried all sorts to test form validation, but cant get any to work. any advice would be appreciated. thanks
CodePudding user response:
You have to store the result of $this->post
in a variable and use that.
$applicationRef = Application::inRandomOrder()->pluck('reference')->first();
$response = $this->post(
'http://website.test/applications/'.$applicationRef.'/update',
['title' => null]
);
$response->assertSessionHasErrors('title');