question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Asserting on all items in an iterable with `.all`

See original GitHub issue

The 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
keithamuscommented, Jun 9, 2018

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!

0reactions
silkentrancecommented, Jun 13, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I assert an Iterable contains elements with a certain ...
All I care about verifying is that the List<MyItem> , or any Iterable , contains two MyItem instances, whose "name" properties have the...
Read more >
chai-iterator: Assertions for iterable objects - Chai
chai-iterator extends the Chai assertion library with methods for testing iterable objects. ... And we can pass any iterable as our expected values...
Read more >
Python's assert: Debug and Test Your Code Like a Pro
The all() assertions check if all the items in an input iterable are truthy, while the any() examples check if any item in...
Read more >
Strikt Cheatsheet - gists · GitHub
Iterable .all() : traverses to collection members and applies assertions to all items; Iterable .map() : allows assertions to be mapped to each...
Read more >
unittest.mock — mock object library — Python 3.11.1 ...
Mock and MagicMock objects create all attributes and methods as you access ... If side_effect is an iterable then each call to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found