Closed fschwiet closed 9 years ago
Issued was observed on version 1.3.4
Ok, though I was quite certain the given test was failing before (using .Text()), it is passing for me now. I have no idea why. It seems .InnerText is still behaving badly though, which is what I was using in the code I am trying to fix. With the tests below, at version 1.3.4, TextIncludesSubElements passes while test InnerTextIncludesSubElements fails. I sear TextIncludesSubElements (formerly called Misc) was failing before, but, its hard to explain why it would change and easier to conclude I made a mistake in my observations.
[Test]
public void TextIncludesSubElements ()
{
CsQuery.CQ document = "<td class=\"vtable-word\">est<span class=\"conj-irregular\">á</span></td>";
var td = document ["td"].First ();
// https://github.com/jamietre/CsQuery/issues/186
Assert.AreEqual ("está", td.Text());
}
[Test]
public void InnerTextIncludesSubElements ()
{
CsQuery.CQ document = "<td class=\"vtable-word\">est<span class=\"conj-irregular\">á</span></td>";
foreach (var element in document["td"]) {
Assert.AreEqual ("está", element.InnerText);
}
}
I can use element.Cq().Text() instead of .InnerText to get the result I want now. I don't know why I saw .Text() misbehaving, but I will assume I was wrong on that and close this issue out.
(I still expected .InnerText to behave differently, but CsQuery is your design I'm not sure if that makes sense for you)
When using jQuery or the DOM, .text() and .innerText include the text of inner DOM elements. In the below example, observe the contents of the inner are included:
in CsQuery, the nested elements are not included in .Text() or .InnerText. Below is a failing test, the .Text() result equals "est", not including the s contents as I'd expect.