BenoitDesrosiers
7 months ago
504
3
Testing

view testing returns Undefined variable: errors

Posted 7 months ago by BenoitDesrosiers

I'm trying to do an integration test of a show view.

My test is:

$reponse = $this->call('GET', route('something.show',$something->id)); $reponse->assertViewHasAll(['field1', 'field2']);

But it fails with Facade\Ignition\Exceptions\ViewException: Undefined variable: errors

In the view, I have {{ $errors->first('field1') }} (yes, my show view has $errors because I'm using the same sub-blade for show and edit.

The only way I have found to make the test pass is to protect the view with @if(isset($error)) ....

My question is: why is it working when running it normaly, and failing when testing ?

thanks

Please sign in or create an account to participate in this conversation.