-
Hello, I am trying to change the text of multiple inputs at once, and I can't seem to understand how it works. This test passes: [TestMethod]
public void TestMethod1()
{
var cut = RenderComponent<bUnitLightInjectBug.Pages.FetchData>();
IElement a = cut.Find("#test-a");
IElement b = cut.Find("#test-b");
var form = cut.Find("form");
a.Change("aaaaaaaaaaaaaaaaa");
Assert.AreEqual(a.GetAttribute("value"), "aaaaaaaaaaaaaaaaa");
b.Change("bbbbbbbbbbbbbbbbb");
Assert.AreEqual(b.GetAttribute("value"), "bbbbbbbbbbbbbbbbb");
form.Submit();
} And this does not: [TestMethod]
public void TestMethod2()
{
var cut = RenderComponent<bUnitLightInjectBug.Pages.FetchData>();
// changing false/true does not change anything
var inputs = cut.FindAll("input", false);
IElement a = inputs.First(x => x.PreviousElementSibling?.TextContent == "A");
IElement b = inputs.First(x => x.PreviousElementSibling?.TextContent == "B");
IElement form = cut.Find("form");
a.Change("aaaaaaaaaaaaaaaaa");
// using debug I can see the markup was actually changed with the correct value attribute
Assert.AreEqual(a.GetAttribute("value"), "aaaaaaaaaaaaaaaaa"); // this throws
// if we skip the assert, the code below executes but the markup is not even changed
b.Change("bbbbbbbbbbbbbbbbb");
Assert.AreEqual(b.GetAttribute("value"), "bbbbbbbbbbbbbbbbb");
form.Submit();
} This is the test project from earlier. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi again, Yeah, this is a little non-obvious admittedly. What happens is that when you call
So what you are asserting against on line I do have a plan to fix this, but it is not simple by any means. Alternatively, you can usually get around this with some more advanced CSS selectors and just use |
Beta Was this translation helpful? Give feedback.
-
I see, I will try your suggested changes then. Thank you for the explanation!
|
Beta Was this translation helpful? Give feedback.
Hi again,
Yeah, this is a little non-obvious admittedly. What happens is that when you call
Change
, the components render, and a new DOM tree is build, replacing the old one (DOM tree has the IElements in it).Find
actually returns an adapter/wrapper around theIElement
, and this adapter automatically retrieves the new element from the new DOM tree after the call fromChange
.FindAll
does the same, if you do not passfalse
as the second parameter. However, when you pullIElement
s out of theinputs
list, thenFindAll
cannot update those any more, at least not in the current implementation.So what you are asserting against on line
Assert.AreEqual(a.GetAttribute("value"), "aaaaaaaaaaaaaaaaa");