Asserting on all items in an iterable with `.all`
See original GitHub issueThe desire for something like this was first raised in #410 as far as I can tell, but a concrete proposal was never really made there/didn’t go very far.
My basic thinking is that chai already has an all
modifier, but its power seem to be very limited at the moment (to just influencing the keys
assertion). A natural extension of this would seem to be to use all
to require that an assertion holds for all items in an iterable.
I confess to not being familiar with how Chai is implemented, so I don’t know if this would be possible to implement backwards compatibly (and/or if an exception would have to be made for .all.keys
to preserve the current behavior). Maybe someone with more background can weigh in on the implementation options there. Here’s the syntax that I think would be nice, though:
expect([a, b, c]).to.all.equal(3);
expect([a, b, c]).to.all.satisfy(it => it > 2);
expect([a, b, c]).to.all.throw(); // etc. can imagine any assertion after the all.
expect([a, b, c]).to.all.have.all.keys('a', 'b'); // posible?
expect([a, b, c]).to.all.have.any.keys('a', 'b'); // posible?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:8 (2 by maintainers)
Top GitHub Comments
Hey @ethanresnick thanks for this issue!
This is an awesome idea! We’re definitely going to be implimenting this for Chai 5 - but for now we’ll close this, as there’s going to be a bunch of work done for Chai 5, and so we’ve set up a project board for this. https://github.com/chaijs/chai/projects/2 is the roadmap board now. We’ll be using that to track this feature.
Thanks for your input on chai!
ERRONEOUS/OBSOLETE: see #1166.
@keithamus maybe I was in the wrong movie 😄, just read the summary again and was wondering what got me started in the first place.
all
perhaps.I will open a new issue for this and will copy/move all of the existing comments to that issue.