Courses

Testing in Laravel 11: Advanced Level

Disable Exception Handling

Summary of this lesson:
- Disable exception handling in tests
- Use --without-exception-handling flag
- Implement withoutExceptionHandling() method
- Get more detailed error information
- Improve test error visibility

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 31 lessons of this course? (74 min read)

You also get:

  • 73 courses
  • Premium tutorials
  • Access to repositories
  • Private Discord