How can I test for an ordered subset with gaps between the elements?
See original GitHub issueI have an array of Redux actions, some of which I care about and some which I don’t. I do care about the order (an async request had better come before a response! 😇 ).
I tried code like this with Chai 4.1.2:
chai.expect([1,2,3,4,5]).to.include.ordered.members([1,3,5]);
chai.expect([1,2,3,4,5]).to.deep.include.ordered.members([1,3,5]); // also
Which yields the error:
expected [ 1, 2, 3, 4, 5 ] to be an ordered superset of [ 1, 3, 5 ]
Reading through #717, it appears that this was deliberate:
expect([1, 2, 3]).to.include.ordered.members([1, 2]); expect([1, 2, 3]).to.include.ordered.members([2, 3]);
I’m leaning toward only the first passing, as I suspect it’s a more common use case to test that an array begins with an ordered subset.
What is the correct syntax to say “element A must come before B, which must come before C, which …”?
Thanks for the great library!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:6 (4 by maintainers)
Top Results From Across the Web
How to find if a list is a subset of another list in order? [closed]
Use a simple loop to iterate through both lists in order. At the end, check if all elements of the potential subset list...
Read more >Find whether an array is subset of another array
Naive Approach to Find whether an array is subset of another array. Use two loops: The outer loop picks all the elements of...
Read more >Chapter VIII Ordered Sets, Ordinals and Transfinite Methods
In this chapter, we will look at certain kinds of ordered sets. If a set is ordered in a reasonable way,. \ then...
Read more >1.5 Logic and Sets
There is a natural relationship between sets and logic. If A is a set, then P(x)="x∈A'' is a formula. It is true for...
Read more >Linearly Independent Subset - an overview
Next, suppose Q is a totally ordered subset of P. Define M to be the union of ... As opposed to writing any...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @shepmaster thanks for the issue.
We’ve added this to our Roadmap https://github.com/chaijs/chai/projects/2! We’ll be releasing chai 5 soon, but for now I’ll close this issue because it is tracked on our roadmap.
Same issue here, albeit not redux.
Actual:
And we test it like this:
But that doesn’t assert on the order.