I'm writing tests for a site made with Laravel Jetstream and Livewire, but the default action message component included in the view is giving me errors when trying to test the view.
To be clear, the view i'm trying to test is a Livewire component view, so probably Livewire automagic stuff is involved in my use case.
To be even more clear, i'm not getting any errors with the Livewire public properties: i mean that i'm passing every other data necessary to the view without any problem.
The test
public function testTheViewTest()
{
$view = $this->view(
'livewire.permission-request.details',
[
'data' => $data,
]
);
$view->assertSee( /* stuff */);
}
The error
Undefined variable: _instance (View: /var/www/resources/views/vendor/jetstream/components/action-message.blade.php) (View: /var/www/resources/views/vendor/jetstream/components/action-message.blade.php)
at storage/framework/views/c49f88cce68697934e3155ad448667e473748274.php:12
8▕ } ?>
9▕ <?php unset($__defined_vars); ?>
10▕
11▕ <div x-data="{ shown: false, timeout: null }"
➜ 12▕ x-init="window.livewire.find('<?php echo e($_instance->id); ?>').on('<?php echo e($on); ?>', () => { clearTimeout(timeout); shown = true; timeout = setTimeout(() => { shown = false }, 2000); })"
13▕ x-show.transition.opacity.out.duration.1500ms="shown"
14▕ style="display: none;"
15▕ <?php echo e($attributes->merge(['class' => 'text-sm text-gray-600'])); ?>>
16▕ <?php echo e($slot ?? 'Saved.'); ?>
+2 vendor frames
3 storage/framework/views/c49f88cce68697934e3155ad448667e473748274.php:12
ErrorException::("Undefined variable: _instance (View: /var/www/resources/views/vendor/jetstream/components/action-message.blade.php)")
+2 vendor frames
6 storage/framework/views/c49f88cce68697934e3155ad448667e473748274.php:12
ErrorException::("Undefined variable: _instance")
Consideration
I'm quite sure the $_instance
missing here is the Livewire component instance, so i've tried to add a
'_instance' => (object)['id' => 1]
to the data passed to the view, just to give it an object to use in the <?php echo e($_instance->id); ?>
section, but i still get the same error just as if my _instance
value is not detected.
Probably passing a new LivewireComponent()
as value will lead to the same error without any new clue.
Aucun commentaire:
Enregistrer un commentaire