percyhanna / chai-react

Chai assertions for React
MIT License
40 stars 3 forks source link

Assertions on collections vs. single items #10

Open jagregory opened 9 years ago

jagregory commented 9 years ago

Hey, I'm liking the direction this library is heading. I think it has great potential to tidy up my React tests :+1:

The only downside (and this is maybe rquery rather than chai-react, or something in between) the API is currently a bit awkward in places where it's unclear whether a method works against a collection or a single item.

For example:

const child = $node.find('.value')

expect(child).to.have.prop('id') // fails, need to use child[0]
expect(child.text()).to.equal('hi') // works, no child[0] needed

Coming from JQuery, all methods are available on the collection interface and just pass through to the first item if there is only one.

percyhanna commented 9 years ago

I assume you're referring to using rquery and chai-react together? I found myself wanting some better assertions myself while I was writing some tests today.

chai-react (or a new chai-rquery plugin) would need to have unique assertion names to avoid collision with other plugins like chai-jquery.

Definitely interested in exploring this in more depth.