CUT Markup does not match IElement Markup #1302
-
I can try to recreate a runnable example, but first wanted just to describe and show what is going on - if the solution can be more simply figured out that way. I have written a test that is verifying that a Form in the Completed state should be read only. I do that by checking that there are no form buttons displayed and that all inputs are either disabled or readonly. For some reason my test is failing only on certain run throughs where it seems like the IElements I query are not reflecting the CUT's markup. Do you know why this could be or if I am doing something wrong? EDIT: This also only seems to fail when running all my test classes in one go rather than each test class individually. This makes me suspicious that something is at play similar to in #1247 with the service dependencies. If so...not really sure a great way around that. [Theory, AutoData]
public void SubmittedForm_ShouldBeReadOnly(Form form)
{
// [Arrange]
form.StatusID = Status.Completed;
IFormService formService = Services.GetRequiredService<IFormService>();
formService.Form = form;
var cut = RenderComponent<FormComponent>();
// [Act]
var formButtons = cut.FindComponent<FormButtons>();
var textBoxFormElements = cut.FindAll("span.k-textbox input, input[inputmode='decimal']");
var allOtherFormElements = cut.FindAll("span.k-dropdownlist, span.k-textarea, span.k-combobox, input.k-checkbox, li.k-radio-item");
// [Assert]
Assert.Empty(formButtons.Markup);
foreach (var element in textBoxFormElements)
{
Assert.True(element.HasAttribute("readonly"));
}
foreach(var element in allOtherFormElements)
{
Assert.Contains("k-disabled", element.GetAttribute("class"));
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hey @rileyharris7, some small questions for clarification:
|
Beta Was this translation helpful? Give feedback.
Regarding 2: Yes.
I would just refer to the docs here, as they explain it quite well: https://bunit.dev/docs/interaction/awaiting-async-state.html and https://bunit.dev/docs/verification/async-assertion.html
Let me know if you have questions - it might be also worth sharing your component under test (in a minimal fashion) to know what is going on.
A word of advise: For testing purposes, try to mock out asynchronous stuff as much as you can and make sense in your test.
If you can create mocks/fakes that return
Task.FromResult
you don't have to deal with asynchronous stuff.