A testing library for Blazor components. Get started testing Blazor components at https://bunit.dev
IRenderedComponent<Dialog> cut = RenderComponent<Dialog>(ps => ps.Add(p => p.HeaderTitle, headerName));
("HeaderTitle", headerName)
, can be more terse.
cut.Find("input-field css selector").Change("NEW VALUE");
works
hi @therubble_twitter, I cant remember, but I think the EditForm provides a context, so you just need to give it a model. Something like thus (warning, untested code):
// using the new RenderTree option in beta 11 (https://bunit.egilhansen.com/docs/providing-input/root-render-tree.html)
using var ctx = new TestContext();
ctx.RenderTree.Add<EditForm>(ps => ps.Add(p => p.Model, myModel));
var cut = ctx.RenderComponent<MyComponent>();
or
using var ctx = new TestContext();
var cut = ctx.RenderComponent<EditForm>(ps => ps
.Add(p => p.Model, myModel)
.AddChildContent<MyComponent>()
);
@{
if (ChildContent != null)
{
@ChildContent(Model)
}
else
{
<!-- Output a placeholder -->
<div>
<InputNumber @bind-Value="Model.BindableValue" disabled="@Model.ReadOnly"></InputNumber>
<ValidationMessage For="@(() => Model.BindableValue)"></ValidationMessage>
<SourceSystemMessages Model="Model.SourceSystemMessages"></SourceSystemMessages>
</div>
}
}
@code{
[Parameter]
public virtual RenderFragment<Core.DecimalValue> ChildContent { get; set; }
[Parameter]
public virtual Core.DecimalValue Model { get; set; }
}
var cut = RenderComponent<EditForm>(ps => ps
.Add<MyForm, EditContext>(p => p.ChildContent, ctx => myformParams => myformParams.Add(x => x.Model, ctx.Model))
);