I was surprised to find that the responses here do not contain references to official documentation.
Disable build tools
In Laravel tests you can disable the automatic inclusion of the asset bundler that Laravel uses to compile frontend assets (JavaScript, CSS, etc.). These methods are useful when you are testing your application and want to prevent Laravel from trying to load unnecessary frontend-related files.
Vite (supported Laravel 9.x or above)
Starting from version 9.x
, Laravel officially recommends using it paired with Vite. Therefore, the withoutVite
command has replaced the previous withoutMix
command.
If you would prefer to mock Vite during testing, you may call the withoutVite
method, which is available for any tests that extend Laravel's TestCase
class:
test('without vite example', function () {
$this->withoutVite();
// ...
});
Webpack (supported from Laravel 6.x to 8.x)
From Laravel 9.x need migrating back for Webpack using, but by default, with the higher versions, you need the guides related to Vite.
If you would prefer to mock Webpack during testing, you may call the withoutMix
method, which is available for any tests that extend Laravel's TestCase
class:
test('without webpack example', function () {
$this->withoutMix();
// ...
});
Disable Laravel Functions
I only highlighted one thing from the documentation (HTTP tests), but there is much more in it that we can disable depending on the situation.
Exception Handling
You may totally disable exception handling for a given request by invoking the withoutExceptionHandling
method before making your request:
$response = $this->withoutExceptionHandling()->get('/');
Assert
instead ofAssertableInertia
? The older documentation usesAssert
. The documentation on testing on the website (inertiajs.com/testing) is very light and suggests that you should follow the old documentation for now. – Kantos