Livewire Media Selector
Guide
Configuration
Livewire Integration
Performance
GitHub
Guide
Configuration
Livewire Integration
Performance
GitHub
  • Guide

    • Getting Started
    • Configuration Reference
    • Attribute Reference
    • Livewire Integration
    • Performance Playbook
    • Testing Recipes

Testing Recipes

The package ships with Pest-powered feature tests.
Use these examples to test your own integrations and keep regressions out of production.

Faking storage

Storage::fake('public');

$media = Media::create([
    'disk' => 'public',
    'path' => 'media/example.jpg',
    'filename' => 'example.jpg',
    'collection' => 'gallery',
    'mime' => 'image/jpeg',
]);

expect(Storage::disk('public')->exists($media->path))->toBeTrue();

Livewire component tests

Livewire::test(MediaSelector::class)
    ->call('openModal')
    ->assertSet('showModal', true)
    ->set('selectedIds', [$media->id])
    ->call('closeModal');

Trait helpers

$post = TestHasMediaModel::create();
$post->attachMedia([['id' => $media->id]], 'gallery');

expect($post->getMediaUrl('gallery'))->toEndWith('example.jpg');

Assertions

  • assertSee() for modal labels and translated strings.
  • assertHasErrors() when validating uploads.
  • assertSet() to verify Livewire property mutations.

Run the entire suite with:

composer test
Edit this page
Updated on: 11/12/25, 2:23 AM
Contributors: Pshtiwan Mahmood
Prev
Performance Playbook