chai-react icon indicating copy to clipboard operation
chai-react copied to clipboard

Assertions on collections vs. single items

Open jagregory opened this issue 10 years ago • 1 comments

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.

jagregory avatar Sep 10 '15 06:09 jagregory

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.

percyhanna avatar Sep 10 '15 06:09 percyhanna