nathanboktae / chai-dom

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

[Feature Request] Add support for substring matching #4

Closed rupurt closed 9 years ago

rupurt commented 9 years ago

Hi,

Thanks for the awesome work on this chai addon.

It would be awesome if this library had support for matching a substring of text. e.g.

// <div id="my-elm">FooBar</div>
myElm = document.querySelector("#my-elm");
expect(myElm).to.contain.text("Foo");
rupurt commented 9 years ago

Submitted in #5

nathanboktae commented 9 years ago

5 has been merged. Good idea. We should also support regular expressions too. a PR for another day.

rupurt commented 9 years ago

@nathanboktae regex would be great. Do you prefer leveraging matches or having the method take a regex as an argument? i.e.

expect(myElm).to.contain.text.matches(/Fo{1,2}/);

vs

expect(myElm).to.contain.text(/Fo{1,2}/);
nathanboktae commented 9 years ago

I'd prefer the later. The former if it was using matching instead of matches since it reads as proper English would be alright too.