bUnit-dev / bUnit

bUnit is a testing library for Blazor components that make tests look, feel, and runs like regular unit tests. bUnit makes it easy to render and control a component under test’s life-cycle, pass parameter and inject services into it, trigger event handlers, and verify the rendered markup from the component using a built-in semantic HTML comparer.
https://bunit.dev
MIT License
1.13k stars 105 forks source link

AngleSharp.Html.Dom.HtmlButtonElement.IsDiabled() appears to be incorrectly stating button is disabled after a Click() action is performed #656

Closed KCAndersen closed 2 years ago

KCAndersen commented 2 years ago

Describe the bug

The IsDisabled attribute of the IElement does not match what is seen in the rendered html. This may be more of an AngleSharp issue than a Bunit issue, but in case it can be overcome within Bunit, figured it might be worth posting. Or perhaps I'm simply misunderstanding expectations.

Example: Testing this component:

            <button type="button" @onclick="() => editingDisabled = !editingDisabled">Toggle Editing</button>

<EditForm model="associate" OnValidSubmit="SubmitFormAsync" class="edit-form">
                <div class="row">
                    <div class="col line-wise">
                        <DataAnnotationsValidator/>
                        <button type="submit" aria-disabled="@SubmitDisabled" disabled="@SubmitDisabled">Submit Changes</button>
                    </div>
                </div>
                <ValidationSummary/>
            </EditForm>

With this test:

       var sut = RenderComponent<SamplePage>(param => param
            .Add(p => p.associateId, 10));
        var button = sut.FindAll("button");
        var toggleButton = button.Where(b => b.TextContent.Equals("Toggle Editing")).FirstOrDefault();
        var buttonToVerify = button.Where(b => b.TextContent.Equals("Submit Changes")).FirstOrDefault();

        //act
        toggleButton.Click();

        //assert
        Assert.IsFalse(buttonToVerify.IsDisabled());

Results in this output:

Assert.IsFalse failed. 

Expected behavior: In the above example, if you debug sut.markup, it will show

<button type="submit" aria-disabled=disabled>Submit Changes</button>

prior to the toggleButton.Click(); after that action, the aria-disbaled element is removed from the markup of sut. I would expect buttonToVerify to have its IsDisabled = false at the same time.

Version info:

Additional context:

Just to validate it wasn't a pointer (or lack of pointer) issue I've also set the variable definition to be after the toggleButton.Click() action; results were the same.

KCAndersen commented 2 years ago

Whoops. The RefreshableElementCollection that comes out of sut.FindAll does not refresh by default, but apparently can with EnableAutoRefresh turned to True. This resolves my issue. Apologies for the bother!