Skip to content

BUnit doesn't work with MudTooltip #1035

Closed

Description

@kostyrin

BUnit doesn't work with MudTooltip

Good afternoon,

I wrote a sample

Example:
Testing this component:

@using MudBlazor

<p>@text</p>
<MudTooltip>
    <ChildContent>
        <MudMenu id="@_id">
            @{
                <MudMenuItem id="@_id" @onclick=@(() => openDialog("Y", _id))>name</MudMenuItem>
            }
        </MudMenu>
    </ChildContent>
</MudTooltip>

@code {
    private long _id { get; set; } = 1;
    public string text { get; set; }

    private void openDialog(string approval, long id)
    {
        text = "test";
    }
}

With this test:

          using var ctx = new TestContext();
          ctx.JSInterop.SetupVoid("mudPopover.connect", _ => true);
          ctx.Services.AddMudServices();
          var testComponent = ctx.RenderComponent<MudTestComponent>();

          var button = testComponent.Find("button");
          button.Click();
          testComponent.WaitForState(() => testComponent.Instance.text == "test", TimeSpan.FromSeconds(5))

Markup:

<p></p>
<div class="mud-tooltip-root mud-tooltip-inline" blazor:onmouseenter="1" blazor:onmouseleave="2" blazor:onmouseup="3" blazor:onfocusin="4" blazor:onfocusout="5">
   <div id="1" Class="mud-menu" blazor:onmouseenter="6" blazor:onmouseleave="7">
      <button blazor:onclick="8" type="button" class="mud-button-root mud-button mud-button-text mud-button-text-default mud-button-text-size-medium mud-ripple" blazor:onclick:stopPropagation blazor:elementReference=""><span class="mud-button-label"></span></button>
      <div id="popover-443c299a-34de-4546-b6c3-79b04e5c7512" class="mud-popover-cascading-value"></div>
      <div class="mud-overlay" style="" blazor:onclick="9" blazor:onclick:stopPropagation></div>
   </div>
</div>

Results in this output:

doesn't pass the test
Bunit.Extensions.WaitForHelpers.WaitForFailedException : The state predicate did not pass before the timeout period passed. Check count: 1. Component render count: 2. Total render count: 2.

Expected behavior:

When click at the button we will see a message: pass the test

Version info:

  • bUnit version: 1.18.4
  • .NET Runtime and Blazor version: 6.0.11
  • MudBlazor version: 6.2.0

Additional context:
Nothing happened when trying to debug the clicking or when set a break inside openDialog method

Activity

  1. LunicLynx commented on Apr 3, 2023

    @LunicLynx
    Contributor

    Have you tried debugging that your openDialog method is invoked?
    If not, this is probably something inside the MudBlazor library bUnit can't help you with. (async javascript for example).

    Also be aware that this is probably not doing what you expect, in a UnitTest scenario.

    ctx.Services.AddMudServices();
    
  2. egil commented on Apr 3, 2023

    @egil
    Member

    @kostyrin I know MudBlazor uses bUnit to test their components, so I would check in their repo how they test MudTooltip. You can also check out the discussion forum here, others before you have asked about testing components that use Mud.

    I will convert this issue to a QA discussion.

  3. locked and limited conversation to collaborators on Apr 3, 2023
  4. converted this issue into a discussion #1036 on Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions