In a test, should fillForm() be firing afterStateUpdated()?
I have the following field:
and the following test:
On the live site it all works, I assumed this test would have picked it up, however it doesn't.
I'm just wondering is there something I need to do in my test to ensure the afterStateUpdated() is fired? The field is set to live().
8 Replies
Ok, maybe I'm doing something dumb. The code is being called, when I dd() inside of that logic block it fails where I expect. I guess I just expected to be able to assert that that browser event was dispatched, but ->assertDispatched() doesn't seem to be doing what I think it should. Anyone see what i'm doing wrong here?
Alright. After a bunch of poking around, it looks like this works:
I neeeded to use ->set() instead of formFill().
Hopefully this helps someone. 🙂
Yea, for clarity formFill() is the initial state of the form. So it doesn’t ‘update’ the state.
Thank you @awcodes. That makes much more sense now why it wasn't working. 🙂
👍 it’s the same as calling
$this->form->fill()
in a mount method.@CGM Hi, does your test work? I just found out that the
assertDispatched()
syntax to test parameters is not
but
It does.
The spread operator I think does the magic.
Are you using pest?
use function Pest\Livewire\livewire;
I'm using PHPUnit and it works with that:
I just read this syntax in the docs of Livewire, so that's good for me. The other syntax doesn't work for me. But that's ok!
Maybe it's because I have an array as value
Could be. I'm not a huge fan of the Pest addin, but made the mistake of using it for a bunch of tests originally. If it works though I would just go with it. 🙂