Skip to main content

Disable Exception Handling

Premium
3 min read

Let's look at another trick: how to view the test errors slightly differently.


The Problem

Imagine you have a test to check if the record is being seen on the page.

use App\Models\User;
use App\Models\Product;
use function Pest\Laravel\actingAs;
 
beforeEach(function (): void {
$this->user = User::factory()->create();
});
 
test('homepage contains table product', function () {
$product = Product::create([
'name' => 'table',
'price' => 100,
]);
 
actingAs($this->user)
->get('/products')
->assertOk()
->assertSeeText($product->name);
});

In the Controller, you left a typo for the variable.

use App\Models\Product;
use Illuminate\View\View;
 
class ProductController extends Controller
{
public function index(): View
{
$product = Product::all();
 
return view('products.index', compact('products'));
}
}

When you run the test, it gives...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (30 h 33 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.