How do you test repeaters?
I have a test like this but it doesn't seem to work:
8 Replies
It's creating a
shifts
entry immediately with some random UUID, which needs to be filled in.
Ok, I guess this is just not possible 🥲
https://github.com/filamentphp/filament/discussions/6070
GitHub
How to test elements in a repeater? · filamentphp filament · Discus...
I am trying to make sure the first element I feed into my form address repeater is marked primary. When I run the following test $page = Livewire::test(Create::class) ->assertFormExists('for...
Hm this seems like a different issue
Someone else was having a similar issue here https://discord.com/channels/883083792112300104/1151260286490247229
I couldn't replicate it on my end
we have the exact same issue. it was working in v2 but got this error in v3.
in our case it seems that a fast fix is using livewires native
->set($key, $value)
method to set the properties. but i have no clue why ->fillForm()
doesn't work because under the hood it just calls ->set()
would love to hear if someone find's a proper solution for thisOk bringing this up
There's also same question here: https://discord.com/channels/883083792112300104/1150043364792733737
I came to the forum, to post this question, but I found existing questions, so here I am
Most likely people are running into the same issue as me.
In the Webapp, the repeater starts with the default element amount (1) with blank fields
meaning that when we go to test, and use:
instead of having 2 elements, we get a surprise of a fail, because there are 3 elements
when the component mounts, it starts with 1
so, the solution came from @Leandro Ferreira who just investigated and told me:
set the intial state for the repeater, by using for example:
->set('data.answers', null)
so, such sequece must be like:
so now we can ensure that the repeater state will be what we providedwe've found another solution, pointing into the same direction:
this sets the content of data.answers regardless of its previous value, overriding the default(1) item indexed by the uuid
yep, perfect! 🤩