BUnit render component to string deadlocks when using in a Blazor context > 1.18.4
See original GitHub issueI use BUnit to render a component to a string inside a blazor application to support rendering markdown.
Currently i’m using it somewhat like this:
var context = new TestContext();
context.Services.AddFallbackServiceProvider(ServiceProvider);
var rendered = context.Render(ChildContent);
var markup = MarkdownStringUtils.TrimLeftSpaces(rendered.Markup);
var html = Markdown.ToHtml(markup, Pipeline);
_markupString = new MarkupString(html);
All versions after 1.18.4 end in a deadlock rendering the component to html
I guess the crucket is here: https://github.com/bUnit-dev/bUnit/commit/7c156921b5f78023ed435577d1baff6116d4d2f4
I tried to wrap my code into a InvokeAsync etc but still get deadlocked (the render pipeline just never passes Render(ChildContent)
).
I know this is not the primary use case for bunit, and i am waiting for the native net8.0 implementation to render a component to a string from microsoft.
Are there any workarounds i could use?
I could provide a small repro if needed.
Issue Analytics
- State:
- Created 2 months ago
- Reactions:1
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Deadlock when using FindComponent(s) with WaitForX #577
FindComponents where it waits for TestRenderer.renderTreeAccessLock . Version info: bUnit version: 1.3.42 .NET Runtime and Blazor version: .NET ...
Read more >Triggering a render life cycle on a component
With a IRenderedComponent<TComponent>, it is possible to cause the component to render again directly through the Render() method or one of the ...
Read more >Controlling the root render tree
The root render tree, the render tree in which components under test are rendered, can be added to before components are rendered with...
Read more >Passing parameters to components
There are two methods in bUnit that allow passing parameters in C#-based test code: RenderComponent method on the test context, which is used...
Read more >Writing tests for Blazor components
Rendering a component happens through bUnit's TestContext. The result of the rendering is an IRenderedComponent , referred to as a "rendered component", that ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Great. Still have a few other issues to solve before we make a none-preview release.
@egil works 👏👏