A testing library for Blazor components. Get started testing Blazor components at bunit.egilhansen.com/docs/getting-started/
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));
@page
directive in components though, so the navigation step will have to be manual.
var page1 = RenderCompoent<Page1>()
and var page2 = RenderComponent<Page2>()
in the same test class.
TestContext.RenderTree
, if that is how you share state.
cut.WaitForAssertion(() => /* assertion goes here */)
since the test code runs in one thread and the component and renderer in another, to avoid deadlocks.
[Inject]
private IState<CounterState> CounterState { get; set; } https://github.com/mrpmorris/Fluxor/blob/master/Tutorials/02-Blazor/02A-StateActionsReducersTutorial/README.md
IState
, and then in your test, write Services.AddSingleton<IState<CounterState>>(new FakeState(....))