Closed Xeevis closed 4 years ago
Hi Xeevis,
After reading the source for EditForm I am not sure why your first example isnt working. According to the code, if you only provide a Model
everything should be OK.
Can you post your entire test class so I can get the full picture, as well as the version of blazor and bunit?
Hi egil, yeah should, but doesn't in the RenderComponent<>
😓
Version info: bunit 1.0.0-beta-6 .net core 3.1 Solution: BUnitEditForm.zip
public class EditFormTest : ComponentTestFixture
{
[Fact]
public void RenderEditForm()
{
var cut = RenderComponent<EditForm>(
Parameter(nameof(EditForm.Model), new SampleModel())
);
cut.Instance.EditContext.ShouldNotBeNull();
}
}
public class SampleModel
{
public string Username { get; set; }
}
Just did a quick debug, and OnParameterSet
is indeed called. If you look a the code for EditForm, nothing sets the EditContext
property inside OnParameterSet
, so everything is as expected. What is set is the private _fixedEditContext
, which is set by OnParameterSet on this line. See screenshot below:
Closing since this looks like it works as expected.
I'd like to test
EditContext
validation when some custom component is added toEditForm
, but have two issues rendering the EditForm.Can't use Model parameter to create EditContext
It appears EditForm.OnParametersSet() is not called, because if I pass in EditContext directly it works
Can't use ChildContent to include inputs or other components
This throw exception
Any ideas how to get it working? Thanks.