-
I am fairly new to Bunit testing, so I apologize if this seems trivial. We have component that we want to test with the following structure:
I am trying to do something like:
But I don't think this is correct. I only care about what gets rendered below where I wrote our own divs, etc ... I don't think I need to render the mud components or the loading spinner. Do I have to mock or stub those components? Do I need to use If I don't include the code
Then all I see in the cut markup is If I do include that code, then cut is null and the render tree is empty. The component under test is the UserInfoTooltip component. I feel so lost right now. Can someone please point me in the right direction? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Your instincts are not wrong. Ideally, you should not test MudBlazor's logic, that's their job (and they are using bUnit for that btw.). You can substitute MudBlazor components with something else, similar to mocking dependencies when in none Blazor testing. How to do that is covered here: https://bunit.dev/docs/providing-input/substituting-components.html You may not need to do so though, that is, substitute out 3rd party components, if they are not preventing you from rendering. If they are not, just render the component you have created that uses Mud or other 3rd parties, and use `cut.Find("the part of the component I care about") and then assert against that markup. With "popup" components and similar (dialog), your content may not actually be rendered before a user hovers over a section of the markup, so you will not see that in an initial render using bUnit. In that case, it may be easiest to either substitute out the popup component your component under test is using and that way you can access the render fragment that was passed to the popup component in your test. You may also find it useful to watch my presentation that is linked here: https://bunit.dev/docs/getting-started. This may also help: #588 |
Beta Was this translation helpful? Give feedback.
-
Unless I want to test MudPopover, I would never do If you have a component that you have created, which uses MudPopover as a child component, then you are able to substitute it out. In that case, you would do If you want to test a component that you pass as the child content to MudPopover, just render that directly, e.g. |
Beta Was this translation helpful? Give feedback.
@egil , I found the answer here. That answer is in the Mudblazor repo and as a reply to that answer, I posted my final working code.
The solution was to add the component
<MudPopoverProvider />
above the component under test. See below.UserInfoTooltipWrapper.razor