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.

How can I test for an ordered subset with gaps between the elements?

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
keithamuscommented, Jun 9, 2018

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.

1reaction
Izhakicommented, May 22, 2018

Same issue here, albeit not redux.

Actual:

      [ { message: 'fillStyle', args: [ 'transparent' ] },
        { message: 'strokeStyle', args: [ 'black' ] },
        { message: 'strokeStyle', args: [ 'purple' ] },
        { message: 'beginPath', args: [] },
        { message: 'arc', args: [ 140, 100, 50, 0, 6.283185307179586 ] },
        { message: 'stroke', args: [] } ]

And we test it like this:

    expect(ctx.calls).to.deep.include.members([
      { message: 'strokeStyle', args: ['purple'] },
      { message: 'beginPath', args: [] },
      { message: 'arc', args: [140, 100, 50, 0, 6.283185307179586] },
      { message: 'stroke', args: [] },
    ]);

But that doesn’t assert on the order.

Read more comments on GitHub >

github_iconTop 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 >

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