pest-testing
Pest Testing 4
Documentation
Use search-docs for detailed Pest 4 patterns and documentation.
Basic Usage
Creating Tests
All tests must be written using Pest. Use php artisan make:test --pest {name}.
Test Organization
- Unit/Feature tests:
tests/Featureandtests/Unitdirectories. - Browser tests:
tests/Browser/directory. - Do NOT remove tests without approval - these are core application code.
Basic Test Structure
it('is true', function () {
expect(true)->toBeTrue();
});
Running Tests
- Run minimal tests with filter before finalizing:
php artisan test --compact --filter=testName. - Run all tests:
php artisan test --compact. - Run file:
php artisan test --compact tests/Feature/ExampleTest.php.
Assertions
Use specific assertions (assertSuccessful(), assertNotFound()) instead of assertStatus():
it('returns all', function () {
$this->postJson('/api/docs', [])->assertSuccessful();
});
| Use | Instead of |
|---|---|
assertSuccessful() |
assertStatus(200) |
assertNotFound() |
assertStatus(404) |
assertForbidden() |
assertStatus(403) |
Mocking
Import mock function before use: use function Pest\Laravel\mock;
Datasets
Use datasets for repetitive tests (validation rules, etc.):
it('has emails', function (string $email) {
expect($email)->not->toBeEmpty();
})->with([
'james' => 'james@laravel.com',
'taylor' => 'taylor@laravel.com',
]);
Pest 4 Features
| Feature | Purpose |
|---|---|
| Browser Testing | Full integration tests in real browsers |
| Smoke Testing | Validate multiple pages quickly |
| Visual Regression | Compare screenshots for visual changes |
| Test Sharding | Parallel CI runs |
| Architecture Testing | Enforce code conventions |
Browser Test Example
Browser tests run in real browsers for full integration testing:
- Browser tests live in
tests/Browser/. - Use Laravel features like
Event::fake(),assertAuthenticated(), and model factories. - Use
RefreshDatabasefor clean state per test. - Interact with page: click, type, scroll, select, submit, drag-and-drop, touch gestures.
- Test on multiple browsers (Chrome, Firefox, Safari) if requested.
- Test on different devices/viewports (iPhone 14 Pro, tablets) if requested.
- Switch color schemes (light/dark mode) when appropriate.
- Take screenshots or pause tests for debugging.
it('may reset the password', function () {
Notification::fake();
$this->actingAs(User::factory()->create());
$page = visit('/sign-in');
$page->assertSee('Sign In')
->assertNoJavaScriptErrors()
->click('Forgot Password?')
->fill('email', 'nuno@laravel.com')
->click('Send Reset Link')
->assertSee('We have emailed your password reset link!');
Notification::assertSent(ResetPassword::class);
});
Smoke Testing
Quickly validate multiple pages have no JavaScript errors:
$pages = visit(['/', '/about', '/contact']);
$pages->assertNoJavaScriptErrors()->assertNoConsoleLogs();
Visual Regression Testing
Capture and compare screenshots to detect visual changes.
Test Sharding
Split tests across parallel processes for faster CI runs.
Architecture Testing
Pest 4 includes architecture testing (from Pest 3):
arch('controllers')
->expect('App\Http\Controllers')
->toExtendNothing()
->toHaveSuffix('Controller');
Common Pitfalls
- Not importing
use function Pest\Laravel\mock;before using mock - Using
assertStatus(200)instead ofassertSuccessful() - Forgetting datasets for repetitive validation tests
- Deleting tests without approval
- Forgetting
assertNoJavaScriptErrors()in browser tests
More from coollabsio/coolify
tailwindcss-development
Always invoke when the user's message includes 'tailwind' in any form. Also invoke for: building responsive grid layouts (multi-column card grids, product grids), flex/grid page structures (dashboards with sidebars, fixed topbars, mobile-toggle navs), styling UI components (cards, tables, navbars, pricing sections, forms, inputs, badges), adding dark mode variants, fixing spacing or typography, and Tailwind v3/v4 work. The core use case: writing or fixing Tailwind utility classes in HTML templates (Blade, JSX, Vue). Skip for backend PHP logic, database queries, API routes, JavaScript with no HTML/CSS component, CSS file audits, build tool configuration, and vanilla CSS.
185livewire-development
Use for any task or question involving Livewire. Activate if user mentions Livewire, wire: directives, or Livewire-specific concepts like wire:model, wire:click, invoke this skill. Covers building new components, debugging reactivity issues, real-time form validation, loading states, migrating from Livewire 2 to 3, converting component formats (SFC/MFC/class-based), and performance optimization. Do not use for non-Livewire reactive UI (React, Vue, Alpine-only, Inertia.js) or standard Laravel forms without Livewire.
41debugging-output-and-previewing-html-using-ray
Use when user says "send to Ray," "show in Ray," "debug in Ray," "log to Ray," "display in Ray," or wants to visualize data, debug output, or show diagrams in the Ray desktop application.
34developing-with-fortify
Laravel Fortify headless authentication backend development. Activate when implementing authentication features including login, registration, password reset, email verification, two-factor authentication (2FA/TOTP), profile updates, headless auth, authentication scaffolding, or auth guards in Laravel applications.
33laravel-actions
Build, refactor, and troubleshoot Laravel Actions using lorisleiva/laravel-actions. Use when implementing reusable action classes (object/controller/job/listener/command), converting service classes/controllers/jobs into actions, orchestrating workflows via faked actions, or debugging action entrypoints and wiring.
5fortify-development
ACTIVATE when the user works on authentication in Laravel. This includes login, registration, password reset, email verification, two-factor authentication (2FA/TOTP/QR codes/recovery codes), profile updates, password confirmation, or any auth-related routes and controllers. Activate when the user mentions Fortify, auth, authentication, login, register, signup, forgot password, verify email, 2FA, or references app/Actions/Fortify/, CreateNewUser, UpdateUserProfileInformation, FortifyServiceProvider, config/fortify.php, or auth guards. Fortify is the frontend-agnostic authentication backend for Laravel that registers all auth routes and controllers. Also activate when building SPA or headless authentication, customizing login redirects, overriding response contracts like LoginResponse, or configuring login throttling. Do NOT activate for Laravel Passport (OAuth2 API tokens), Socialite (OAuth social login), or non-auth Laravel features.
4