A testing library for Blazor components. Get started testing Blazor components at https://bunit.dev
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))
);
Hey all - hoping someone is able to help out with an issue I'm having writing some tests. I have a cascading parameter that takes some services from DI. I'm trying to create tests for my child component and pass in the CascadingValue which from what I've read seems like it should be as simple as:
var cut = ctx.RenderComponent<Toast>(ComponentParameter.CreateCascadingValue("ParameterName", myValue)
In my situation here myValue is a `Mock<ParentComponent>' but whenever I debug the test the value is null so it's not picking it up
ctx.RenderComponent<Toast>(ps => ps.Add(p => p.ParameterName, myValue));