Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 17:02
    dependabot[bot] synchronize #606
  • 17:02
    dependabot[bot] edited #606
  • 17:02
    dependabot[bot] edited #606
  • 17:01
    egil closed #597
  • 17:01
    egil closed #610
  • 15:09
    dnfadmin commented #610
  • 15:09
    dependabot[bot] labeled #610
  • 15:09
    dependabot[bot] opened #610
  • 13:55
    egil commented #605
  • 10:24
    egil commented #601
  • 10:22
    egil closed #605
  • 10:22
    egil closed #601
  • 10:00
    linkdotnet synchronize #605
  • 09:58
    egil labeled #601
  • 09:46
    egil synchronize #605
  • 09:45
    egil labeled #609
  • 09:44
    egil commented #609
  • 09:21
    dependabot[bot] edited #597
  • 09:20
    dependabot[bot] synchronize #606
  • 09:20
    dependabot[bot] edited #606
gismofx
@gismofx
how-to-bunit.gif
After the string value is changed via the UI and then toggled via the button, the value and text should change. Seems to work via the UI, but not via the test.
gismofx
@gismofx
(Side note, it would be really cool if you could "record" a test. like the user interacts with the UI, then out spits some bunit api code to write a test with)
Egil Hansen
@egilhansen:matrix.org
[m]
@gismofx: I dont mind helping, but I need a minimal reproducable example that I can download and play with to help. If you can, create a QA in the dicsussion forum on GitHub.
gismofx
@gismofx
@egilhansen:matrix.org thanks! I'll put one together.
Egil Hansen
@egilhansen:matrix.org
[m]
🙂
Brett McDonald
@bfmsoft
[Fact]
public void RendersCorrectly() {
    using var ctx = new TestContext();

    var rc = ctx.RenderComponent<EditForm>(
        @<EditForm Model="TestData" >
            <DataAnnotationsValidator />
            <EnumInputSelect Id="TestCountryId"
                @bind-Value="TestData.TestCountry" @bind-Value:event="ValueChanged" />
            <ValidationSummary></ValidationSummary>
        </EditForm>
    );

    rc.MarkupMatches(
        @<form >
            <select id="TestCountryId" class="valid" value="0" >
                <option value="128">Default</option>
                <option value="129">UnitedStates</option>
            </select>
        </form>
    );

    rc.Find("#TestCountryId").Change("129");
    rc.Render();
    rc.MarkupMatches(
        @<form >
            <select id="TestCountryId" class="valid" value="129" >
                <option value="128">Default</option>
                <option value="129">UnitedStates</option>
            </select>
        </form>
    );
}
I am trying to test a component that basically is a fancy Select. I want to test the returned (for default). Then select on option and then test that is has changed. I feel I am close but The RenderComponent doesn't work? Is there a sample to look at?
SQL-MisterMagoo
@SQL-MisterMagoo
@bfmsoft I don't think RenderComponent<T> takes a RenderFragment like that - you probably just want Render(@<...your markup>)
Egil Hansen
@egilhansen:matrix.org
[m]
@SQL-MisterMagoo is correct :)
I choose to just call that method Render since you simple pass in a RenderFragment that you want if to render.
Egil Hansen
@egilhansen:matrix.org
[m]
I admit that Render<TCom>(RenderFragment) might confuse things. That is added as a shorthand for Render(@<MyComp...). FindComponent<MyComp>(). You use it when you need an IRenderedComponent instead of an IRenderedFragment that Render gives you. RenderComponent always return an IRenderedComponent.
Ps. An IRenderedComponent inherit from IRenderedFragment.
Brett McDonald
@bfmsoft
OK, my problem is if I used Render it returns RenderedFragment. I want to call Render later to rerender the component to reflect the Change (if you look at the fragment). Am I doing the process wrong? I would love a sample or something.
Egil Hansen
@egilhansen:matrix.org
[m]
See my comment above Brett
SQL-MisterMagoo
@SQL-MisterMagoo
oh that's nice! there's so much I have to learn still about bUnit, but I like to learn, so that's good
gismofx
@gismofx
@egilhansen:matrix.org I'm having trouble making a minimal example, but the complete example is on my repo https://github.com/gismofx/MudBlazor/blob/77dd2c1d2ee12d868982a20795f59754f4eecfa4/src/MudBlazor.UnitTests/Components/AutocompleteTests.cs#L607
4 replies
Egil Hansen
@egilhansen:matrix.org
[m]
Ok, I'll see if I can get some time to look at this tomorrow. Mind just creating a QA in the bunit discussion forum so i don't forget. It's almost midnight here in Iceland so I'm off to bed
gismofx
@gismofx
ah! get sleep :) Thanks! I actually made a few changes in my local copy that I just pushed to my repo. I will make a post in bunit repo.
goodnight
Egil Hansen
@egilhansen:matrix.org
[m]
Great. And thank!
Egil Hansen
@egilhansen:matrix.org
[m]
hey friends, i'm live streaming some bUnit enhancement work right now. Come join at twitch.tv/egilhansen if you want to help out :)
Manuel Zelenka
@dev-in-disguise
Hey everyone!
Quick question regarding the nuget packages. Right now bunit and bunit.web are basically the same. Therefore the question in one of my projects arose: which of those nuget packages should we use when? Or rather: what was the reasoning behind having a bunit and a bunit.web package?
1 reply
Andrzej Bakun
@Andrzej2_gitlab
Hi guys! I think I have a weird problem. When I test a component that has await element.FocusAsync(), the code never continues. I am not really interested in catching focus event, but I don't understand why it gets stuck there and never continues. For net3.1 I have a JSInterop.SetupVoid("myfocusevent", _ => true).SetVoidResult() but I cannot find anywhere how to handle FocusAsync().
2 replies
Egil Hansen
@egilhansen:matrix.org
[m]
Ok, there should be focusasync support builtin, but it does require you are using bunit's JSInterop and not injecting your own IJSRuntime
Andrzej Bakun
@Andrzej2_gitlab
I am using built in JSInterop. I also saw the link you posted. From what I can tell, this will help me to evaluate if FocusAsync() was called, but this is not what interests me. Unless the fact that I add the validation will also cause bUnit to register that js call?
Egil Hansen
@egilhansen:matrix.org
[m]
If you just want the focus async call to work, just don't set anything up.
Andrzej Bakun
@Andrzej2_gitlab

Anyway, I tried. It didn't work. But informed me that Bunit.JSInvokeCountExpectedException : VerifyInvoke failed: "Blazor._internal.domWrapper.focus" was not called the expected number of times.. So I added this line:

JSInterop.SetupVoid("Blazor._internal.domWrapper.focus", _ => true).SetVoidResult();

Solved my problem. But this is not intended, right?

Egil Hansen
@egilhansen:matrix.org
[m]
What blazor version?
Andrzej Bakun
@Andrzej2_gitlab
net6 rc1
Egil Hansen
@egilhansen:matrix.org
[m]
Hmm so that setupvoid call should already be added by default, so you should not need to do so. Only reason I can see it not working is if MS has changed the JS function being called
Can you share your entire test?
Andrzej Bakun
@Andrzej2_gitlab
Sure. Mind that this is work in progress, I hope to get rid of some of the await Task.Delay.
@using AntDesign.Core.JsInterop.Modules.Components
@inherits AntDesignTestBase
@code {
    public Select_Tags_Tests()
    {
        JSInterop.Setup<AntDesign.JsInterop.DomRect>(JSInteropConstants.GetBoundingClientRect, _ => true)
            .SetResult(new AntDesign.JsInterop.DomRect());                     
        JSInterop.Setup<HtmlElement>(JSInteropConstants.GetDomInfo, _ => true)
            .SetResult(new HtmlElement());
        JSInterop.SetupVoid(JSInteropConstants.AddPreventKeys, _ => true);        
        JSInterop.SetupVoid(JSInteropConstants.AddElementTo, _ => true);        
        #if !NET6_0_OR_GREATER
        JSInterop.SetupVoid(JSInteropConstants.Focus, _ => true).SetVoidResult();
        #else
        JSInterop.SetupVoid("Blazor._internal.domWrapper.focus", _ => true).SetVoidResult();
        #endif        
    }

    [Fact]
    public async Task Single_tag_creation() //issue #1645
    {
        //Arrange

        JSInterop.Setup<OverlayPosition>(JSInteropConstants.OverlayComponentHelper.AddOverlayToContainer, _ => true)
            .SetResult(new OverlayPosition() { Top = 0, Left = 0, ZIndex = 5000, Placement = Placement.BottomLeft });               


        var cut = Render<AntDesign.Select<string, string>>(
        @<AntDesign.Select Mode="tags"
            TItemValue="string"
            TItem="string"        
            EnableSearch>
            <SelectOptions>                        
                <SelectOption TItemValue="string" TItem="string" Value="@("1")" Label="1" />            
            </SelectOptions>
    </AntDesign.Select>
    );
        //Act
        //overlay.
        var input = cut.Find("input.ant-select-selection-search-input");        

        input.Input("A"); //await element.FocusAsync() is called by Select here
        cut.WaitForState(() => cut.Instance.ActiveOption is not null);        


        await Task.Delay(100);
        input.KeyUp("ENTER");
        await Task.Delay(1);
        input.Input("B");
        await Task.Delay(1);
        input.KeyUp("ENTER");
        await Task.Delay(1);
        input.Input("C");
        await Task.Delay(1);
        input.KeyUp("ENTER");
        await Task.Delay(1);
        var addedTags = cut.FindAll("span.ant-select-selection-item-content")
            .Where(d => d.TextContent.Trim() == "B");
        //Assert
        addedTags.Should().HaveCount(1);
    }
}
input.Input("A") - await element.FocusAsync() is called by Select here
this test is passing in net5 & in net6 if I manually do the JSInterop.SetupVoid("Blazor._internal.domWrapper.focus", _ => true).SetVoidResult()
Egil Hansen
@egilhansen:matrix.org
[m]
Hmm that weird. You should not need that for .net 6
Andrzej Bakun
@Andrzej2_gitlab
Yeah, I thought so. I am being a bit of a nuisance today :smirk:
Anyway, I am at your disposal.
Egil Hansen
@egilhansen:matrix.org
[m]
Take a look at the test that verifies the FocusAsync support, and see if there are test cases that is missing:
https://github.com/bUnit-dev/bUnit/blob/main/tests/bunit.web.tests/JSInterop/InvocationHandlers/FocusAsyncInvocationHandlerTest.cs
The FocusingComponent is at the bottom of that file.
Andrzej Bakun
@Andrzej2_gitlab
Hmm...I am passing to FocusAsync a boolean. In my case it is default, at at some point I do it explicitly. Could that be it? The boolean stands for PreventDefault and is a part (at least was) of the overload on ElementReference.FocusAsync(bool preventDefault)
You don't seem to have that scenario in your tests
Egil Hansen
@egilhansen:matrix.org
[m]
Ahh i might be missing. If you want to add that it's probably a fairly simple PR 😉
Andrzej Bakun
@Andrzej2_gitlab
:smile: sure, I will try to do that. Let me first hook your repo to my project to play around a bit.
btw when I tried net6 rc2 I got a ton of errors with all SetupVoids not registering and wanting an interface (smth like IJSVoidResult but I am not sure). Did you get that kind of error?
Egil Hansen
@egilhansen:matrix.org
[m]
Yeah, it's fixed in the preview release of bunit
1.3.30-preview iirc