Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Added test for emitting events
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbaljet committed Jan 16, 2024
1 parent 87c5b72 commit 851f7f3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/resources/views/components/emit.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script setup>
const emit = defineEmits(['trigger'])
const trigger = () => {
emit('trigger')
}
</script>

<button @click="trigger">Trigger</button>
13 changes: 13 additions & 0 deletions app/resources/views/emit.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<x-layout>
<script setup>
const show = ref(false)
function toggle() {
show.value = !show.value
}
</script>

<x-emit @trigger="toggle" />

<h2 v-if="show">Triggered</h2>
</x-layout>
1 change: 1 addition & 0 deletions app/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
Route::view('/component-import', 'component-import');
Route::view('/dynamic-component-import', 'dynamic-component-import');
Route::view('/change-blade-prop', 'change-blade-prop');
Route::view('/emit', 'emit');
Route::view('/dynamic', 'dynamic')->withoutMiddleware(SubstituteBindings::class);
Route::view('/form', 'form');
Route::view('/props-in-template', 'props-in-template');
Expand Down
20 changes: 20 additions & 0 deletions app/tests/Browser/EmitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Tests\Browser;

use Laravel\Dusk\Browser;
use Tests\DuskTestCase;

class EmitTest extends DuskTestCase
{
/** @test */
public function it_can_bind_a_listener_to_an_emit_event()
{
$this->browse(function (Browser $browser) {
$browser->visit('/emit')
->assertMissing('h2')
->press('Trigger')
->assertSeeIn('h2', 'Triggered');
});
}
}

0 comments on commit 851f7f3

Please sign in to comment.