Skip to content

How to test rendering a bound value in a razor based test into a non blazor component. #1282

Answered by linkdotnet
wk-done asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for providing the bigger picture - now with some more details, yes the way you try to achieve that isn't really working (for maybe not obvious reasons).

Your call to cut.Render(@</>) will, as you noticed on SO, also create a IRenderedComponent<IComponent>. The component is from bUnit.

To make your scenario work, you can refactor all the content inside Render in its own (test)component. And call the test like that:

var cut = Render(@<FormComponent></FormComponent>);

Or if you need the strongly typed IRenderedComponent<T>:

var cut = Render<FormComponent>(@<FormComponent></FormComponent>);

That will make your test immediately!

Now - why doesn't the original version work out of the box…

Replies: 1 comment 2 replies

Comment options

linkdotnet
Nov 19, 2023
Maintainer Sponsor

You must be logged in to vote
2 replies
@wk-done
Comment options

@egil
Comment options

egil Nov 19, 2023
Maintainer

Answer selected by wk-done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants