How to test specific validation errors in php unit thrown in validation error ? with below code we could check session has errors, but not the exact error
$this->assertSessionHasErrors();
Advertisement
Answer
Got the answer
$errors = session('errors'); $this->assertSessionHasErrors(); $this->assertEquals($errors->get('name')[0],"Your error message for validation");
$errors is MessageBag object which stored in laravel session when validation error thrown using $errors->get(‘name’) you could see all the validation errors as an array