-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
toHaveTextContent should ignore whitespace #9
Comments
Actually, |
That fix was not done in |
No, I was just suggesting while you're working on this you could do that as well. Perhaps we should also expose the |
@kentcdodds wouldn't there be a problem if two packages depend on each other? |
I think that's actually allowed. But I'm thinking that |
-- Removed idea about using |
From @noinkling: This change [#56] breaks testing for text within child elements (nested text), because you switched to using Example: <div class="error">
<ul>
<li>Email format is invalid</li>
</ul>
</div> I just want to write something like Since it now fails, the best I can come up with is something like |
From @kentcdodds:
I don't think that would have worked before. The regex is how I would have done that before and now 🤔 |
Hrm, Line 5: of get-node-text filters out all non TEXT_NODES. So it would only currently get one level deep of text. If we switch the Example: @kentcdodds is This however, would only normalize one level deep though, so it wouldn't solve the issue. |
The normalization was moved to: https://github.com/kentcdodds/dom-testing-library/blob/863741a204bca67c63ca3944770727e5afb071d2/src/matches.js#L39-L46 So getNodeText no longer normalizes the text. (testing-library/dom-testing-library#31) Hrm, Maybe we could use |
Why not just normalize the @kentcdodds Well |
That's a really good point haha! |
🎉 This issue has been resolved in version 2.0.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Thanks for the fix 🙂 |
As @smacpherson64 predicted, this broke a lot of our tests... Is that allowed under SemVer?
|
@malixsys I'm so sorry. I'm not sure how you're specifying jest-dom's version number, but this was indeed published as a breaking change, and it's the breaking change that switched jest-dom from v1.x to v2. I think that would not violate SemVer terms. Maybe I'm missing something. Can you clarify what version you're using that broke your tests, and under which version they used to work? Your code snippet above does not give much information. |
@gnapse Ah yes, indeed! Sorry, thought this was in 2.0.1! No worries, 2.x has been put in the code debt column for now... :) |
jest-dom
version: 1.0.0What you did:
What happened:
Problem description:
This was initially reported in testing-library/react-testing-library#53, and it was really about a bug in testing-library/dom-testing-library#19. However, this also applies to a piece of code in jest-dom. The custom matchet
.toHaveTextContent
should also ignore a node's whitespace in its text content before determining if the text matches the expectation.Suggested solution:
Normalize the text of a node before using to match it with the expected text. Similar to what was done in testing-library/dom-testing-library#19
The text was updated successfully, but these errors were encountered: