Skip to content

InputDate / InputNumber handling #496

Closed

Description

@LordBenjamin

Describe the bug

We are observing a difference in behaviour when running BUnit tests from Visual Studio and dotnet test.

This affects calling Change("value") on InputDate and InputNumber.

These work as expected in the Visual Studio Test Explorer. However, no value appears to be set on the <input> element when run via dotnet test. This is not consistent - sometimes the tests pass / fail with no modification in between runs.

dotnet test "Test.csproj" --configuration Release

Example:
Testing this component:

<InputDate Class="form-control" id="delivery-date" @bind-Value="ViewModel.Item.DeliveryDate" />

With this test:

var deliveryDateField = component.Find("#delivery-date");
deliveryDateField.Change("2021-09-20");
deliveryDateField.MarkupMatches("<input id=\"delivery-date\" type=\"date\" class=\"form-control\" value=\"2021-09-20\"  >");

Results in this output:

  The following errors were found:
    1: The value of the attribute input(0)[class] and actual attribute input(1)[class] are different.
    2: The value of the attribute input(0)[value] and actual attribute input(1)[value] are different.

  Actual HTML:
  <input id="delivery-date" type="date" class="form-control valid" value=""  >

  Expected HTML:
  <input id="delivery-date" type="date" class="form-control modified valid" value="2021-09-20">

Expected behavior:

Expect the value of the <input> element to be consistently set to the value specified when calling Change().

Version info:

  • bUnit version: 1.2.49
  • .NET Runtime and Blazor version: 6.0 RC1
  • OS type and version: Windows 10 - 19042.1165

Additional context:

We are working to identify a minimal reproduction. Any ideas on anything we can try would be appreciated.

Adding Thread.Sleep(1000) between calling Change() and MarkupMatches() appears to reduce (or possibly prevent) failure - is this timing / asynchrony related?

Activity

  1. egil commented on Sep 21, 2021

    @egil
    Member

    Hi @LordBenjamin, thanks for a well described issue.

    If there is an asynchronous re-render being triggered by Change, then you might need to use WaitForAssertion, since that synchronizes between the render thread and the test thread. Learn more about it here: https://bunit.dev/docs/verification/async-assertion

    var deliveryDateField = component.Find("#delivery-date");
    deliveryDateField.Change("2021-09-20");
    
    component.WaitForAssertion(() => deliveryDateField.MarkupMatches(@"<input id=""delivery-date"" type=""date"" class=""form-control modified valid"" value=""2021-09-20"" />");

    Try this and let me know how it goes.

  2. LordBenjamin commented on Oct 3, 2021

    @LordBenjamin
    Author

    Thanks for the suggestion @egil. WaitForAssertion() seems to be what we were looking for!

  3. locked and limited conversation to collaborators on Oct 3, 2021
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