Skip to content
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("") matches element with non-empty content #104

Closed
alexkrolick opened this issue May 10, 2019 · 5 comments · Fixed by #138 or cds-snc/report-a-cybercrime#826
Closed
Labels

Comments

@alexkrolick
Copy link
Contributor

alexkrolick commented May 10, 2019

v3.2.2

const el = document.createElement("div")
el.textContent = "0"
expect(el).toHaveTextContent("") // passes, should be error
alexkrolick added a commit that referenced this issue May 10, 2019
alexkrolick added a commit that referenced this issue May 10, 2019
alexkrolick added a commit that referenced this issue May 10, 2019
@alexkrolick
Copy link
Contributor Author

alexkrolick commented May 10, 2019

Will add a repro test case, the example I tried passed (unexpectedly)

@gnapse
Copy link
Member

gnapse commented May 10, 2019

Is this happening only with the string "0"? Because from the code I think any string will match .toHaveTextContent(''). This is all ultimately determined here, and any string .includes('').

@alexkrolick
Copy link
Contributor Author

Ah, indeed, it fails to throw for other strings.

@alexkrolick alexkrolick changed the title toHaveTextContent("") matches element with "0" as textContent toHaveTextContent("") matches element with non-empty content May 10, 2019
@alexkrolick
Copy link
Contributor Author

alexkrolick commented May 10, 2019

I don't think it should use includes here - use a regex for partial matches, or provide something like toContainText which is explicitly partial

kandros added a commit to kandros/jest-dom that referenced this issue Oct 5, 2019
gnapse pushed a commit that referenced this issue Oct 7, 2019
* throw when matching against empty string sugget toBeEmpty

fix #104

* allow empty content to match empty string
@gnapse
Copy link
Member

gnapse commented Oct 7, 2019

🎉 This issue has been resolved in version 4.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants