nathanboktae / chai-dom

DOM assertions for the Chai assertion library using vanilla JavaScript
Other
76 stars 26 forks source link

Consider using innerText instead of textContent for `text` matching #48

Closed yads closed 3 years ago

yads commented 3 years ago

Consider the following HTML:

<div>
  <span>foo</span>
  <span>bar</span>
</div>

The textContent of the div would be "\n foo\n bar\n", however the actual rendered text that's likely relevant is just "foo bar". Is there an appetite to switch the text matcher to use innerText or at least provide an option to use it instead of textContent maybe something like the following?

expect(element).to.have.rendered.text('foo bar');

I can put together a PR for this if this is something you're interested in supporting @nathanboktae

nathanboktae commented 3 years ago

Great suggestion. I would definitely take that PR!

It may even be worth it to make a breaking change in a future major version to use innerText instead. chai-dom started out in 2015 before Firefox supported innerText.

yads commented 3 years ago

Awesome @nathanboktae I'll put it together for you. I guess for the moment I'll add the rendered option?

nathanboktae commented 3 years ago

Yup the rendered option so we can immediately use it would be best, thanks.

On Fri, Feb 19, 2021 at 3:52 PM Vadim Kazakov notifications@github.com wrote:

Awesome @nathanboktae https://github.com/nathanboktae I'll put it together for you. I guess for the moment I'll add the rendered option?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/nathanboktae/chai-dom/issues/48#issuecomment-782462337, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPFVV7AXFJJM3DYTPXUISTS732T7ANCNFSM4X2W5SFA .

nathanboktae commented 3 years ago

Fixed by #50