@@ -290,4 +290,76 @@ public function testComponentEmitsEventWithIncorrectDataFails()
290290 'foo2 ' => 'bar2 ' ,
291291 ]);
292292 }
293+
294+ public function testAssertComponentDispatchBrowserEvent ()
295+ {
296+ $ testComponent = $ this ->createLiveComponent ('component_with_emit ' );
297+
298+ $ testComponent ->call ('actionThatDispatchesABrowserEvent ' );
299+
300+ $ this ->assertComponentDispatchBrowserEvent ($ testComponent , 'browser-event ' )
301+ ->withPayload ([
302+ 'fooKey ' => 'barVal ' ,
303+ 'barKey ' => 'fooVal ' ,
304+ ]);
305+ }
306+
307+ public function testAssertComponentDispatchBrowserEventFails ()
308+ {
309+ $ testComponent = $ this ->createLiveComponent ('component_with_emit ' );
310+
311+ $ testComponent ->call ('actionThatDispatchesABrowserEvent ' );
312+
313+ $ this ->expectException (AssertionFailedError::class);
314+ $ this ->expectExceptionMessage ('The event "browser-event" payload is different than expected. ' );
315+ $ this ->assertComponentDispatchBrowserEvent ($ testComponent , 'browser-event ' )->withPayload ([
316+ 'fooKey ' => 'barVal ' ,
317+ ]);
318+ }
319+
320+ public function testComponentDispatchesExpectedPartialBrowserEventData ()
321+ {
322+ $ testComponent = $ this ->createLiveComponent ('component_with_emit ' );
323+
324+ $ testComponent ->call ('actionThatDispatchesABrowserEvent ' );
325+
326+ $ this ->assertComponentDispatchBrowserEvent ($ testComponent , 'browser-event ' )
327+ ->withPayloadSubset (['fooKey ' => 'barVal ' ])
328+ ->withPayloadSubset (['barKey ' => 'fooVal ' ])
329+ ;
330+ }
331+
332+ public function testComponentDoesNotDispatchUnexpectedBrowserEvent ()
333+ {
334+ $ testComponent = $ this ->createLiveComponent ('component_with_emit ' );
335+
336+ $ testComponent ->call ('actionThatDispatchesABrowserEvent ' );
337+
338+ $ this ->assertComponentNotDispatchBrowserEvent ($ testComponent , 'browser-event2 ' );
339+ }
340+
341+ public function testComponentDoesNotDispatchUnexpectedBrowserEventFails ()
342+ {
343+ $ testComponent = $ this ->createLiveComponent ('component_with_emit ' );
344+
345+ $ testComponent ->call ('actionThatDispatchesABrowserEvent ' );
346+
347+ $ this ->expectException (AssertionFailedError::class);
348+ $ this ->expectExceptionMessage ('The component "component_with_emit" did dispatch browser event "browser-event". ' );
349+ $ this ->assertComponentNotDispatchBrowserEvent ($ testComponent , 'browser-event ' );
350+ }
351+
352+ public function testComponentDispatchesBrowserEventWithIncorrectDataFails ()
353+ {
354+ $ testComponent = $ this ->createLiveComponent ('component_with_emit ' );
355+
356+ $ testComponent ->call ('actionThatDispatchesABrowserEvent ' );
357+
358+ $ this ->expectException (AssertionFailedError::class);
359+ $ this ->expectExceptionMessage ('The event "browser-event" payload is different than expected. ' );
360+ $ this ->assertComponentDispatchBrowserEvent ($ testComponent , 'browser-event ' )->withPayload ([
361+ 'fooKey ' => 'barVal ' ,
362+ 'fooKey2 ' => 'barVal2 ' ,
363+ ]);
364+ }
293365}
0 commit comments