Livewire: How to test that a component triggered an event via emit

Created on 29 Oct 2019  路  4Comments  路  Source: livewire/livewire

Hey,

I have a component that triggers an event using $this->emit, what options do I have to test it?

Thanks

Most helpful comment

Curious why you closed this, I think Livewire needs an assertion for this kind of thing.

I just added it for you. It's called assertEmitted($event). You can optionally pass in parameters to assert against params, or a callback to assert against a closure of your own.

Hope this helps you!

I'll have it available in the next release, and have it documented shortly.

I want to try and go over the code today and see if I can do a PR to address it after I noticed that it is not available. But you were faster than me.

All 4 comments

Curious why you closed this, I think Livewire needs an assertion for this kind of thing.

I just added it for you. It's called assertEmitted($event). You can optionally pass in parameters to assert against params, or a callback to assert against a closure of your own.

Hope this helps you!

I'll have it available in the next release, and have it documented shortly.

Ok, the assertion has been tagged in a release and the feature is documented here: https://laravel-livewire.com/docs/testing/

Thank you @calebporzio

Curious why you closed this, I think Livewire needs an assertion for this kind of thing.

I just added it for you. It's called assertEmitted($event). You can optionally pass in parameters to assert against params, or a callback to assert against a closure of your own.

Hope this helps you!

I'll have it available in the next release, and have it documented shortly.

I want to try and go over the code today and see if I can do a PR to address it after I noticed that it is not available. But you were faster than me.

Was this page helpful?
0 / 5 - 0 ratings