Testing live() and afterStateUpdated()

for a pest test and testing live(), should assertSet() be used? This is what i am trying, but getting null for the year_built value according to the assertSet output. If i try assertFormSet() of course i just get the original fill values.
test('selecting a property field updates year built and total units field', function () {

ray($this->rfta->property->year_built)->label('rfta property - year_built');
$property = Property::factory()->create();
ray($property->year_built)->label('new property - year_built');

// Simulate selecting a property to see if other fields are updated
/** @phpstan-ignore-next-line */
livewire(RftaResource\Pages\EditRfta::class, ['record' => $this->rfta->id])
->set('property_id', $property->id)
->assertSet('year_built', $property->year_built)
->assertSet('total_units', $property->total_units);
});
test('selecting a property field updates year built and total units field', function () {

ray($this->rfta->property->year_built)->label('rfta property - year_built');
$property = Property::factory()->create();
ray($property->year_built)->label('new property - year_built');

// Simulate selecting a property to see if other fields are updated
/** @phpstan-ignore-next-line */
livewire(RftaResource\Pages\EditRfta::class, ['record' => $this->rfta->id])
->set('property_id', $property->id)
->assertSet('year_built', $property->year_built)
->assertSet('total_units', $property->total_units);
});
8 Replies
Mark Chaney
Mark Chaney8mo ago
im really surprised this isnt documented and/or someone else really hasnt brought it up in discord. Though in general, dont see a lot of detailed pest testing discussion in general, so maybe im just missing something. I do though get a bit detailed in some of my tests.
Dan Harrin
Dan Harrin8mo ago
fillForm() can be used :) its the same as using a form normally
Mark Chaney
Mark Chaney8mo ago
so you can use it multiple times?
Dan Harrin
Dan Harrin8mo ago
yes same as assertFormData or whatever it is
Mark Chaney
Mark Chaney8mo ago
and it will only fill the field that you specify?
Dan Harrin
Dan Harrin8mo ago
yup! it calls set() for each field you pass, with the correct state path prefix
Mark Chaney
Mark Chaney8mo ago
so whats wrong with set() then? Is that even the issue or is it more the assertSet()? Sorry for the 20 questions and thanks. just want to make sure we are in the right direction. currently working on a different project atm
Dan Harrin
Dan Harrin8mo ago
most forms have a state path like data. or mountedActionData. if you use fillForm() we will add that state path to the start of each field name
fillForm([
'name' => 'Dan'
])
fillForm([
'name' => 'Dan'
])
actually does this
set('data.name', 'Dan')
set('data.name', 'Dan')
except you dont have to think about the state path same with assertSet()