Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sameMembers reports members that are actual correct #1146

Closed
LokiMidgard opened this issue Mar 7, 2018 · 4 comments
Closed

sameMembers reports members that are actual correct #1146

LokiMidgard opened this issue Mar 7, 2018 · 4 comments

Comments

@LokiMidgard
Copy link

I've noticed that sameMembers reports members that are included in the expected and actual because they are not on the same position in the array.

Sample:

let actual = [
    'a',
    'b',
    'c',
    'd',
    'e',
];
let expected = [
    'd',
    'c',
    'b',
    'a',
];
assert.sameMembers(actual, expected, 'Fails');

This should and will fail because e is not in expected. However the output will hint at every element but a

      Fails
      + expected - actual

       [
      +  "d"
      +  "c"
      +  "b"
         "a"
      -  "b"
      -  "c"
      -  "d"
      -  "e"
       ]

I would expect an output simular to following, because I didn't used sameOrderedMembers:

      Fails
      + expected - actual

       [
         "a"
         "b"
         "c"
         "d"
      -  "e"
       ]

For completness, the assert does not fail if only the order elements is different, but all and not more elements are in the actuall array.

@meeber
Copy link
Contributor

meeber commented Mar 21, 2018

Just to be clear: the diff is generated by your test runner (e.g., Mocha), not by Chai. However, Chai provides the expected and actual objects that are used by your test runner to generate the diff. There's currently not a good way for Chai to advise the test runner on how the diff should be generated/formatted, other than to manipulate the expected and actual values contained in the AssertionError. (In the future, we hope for Chai to have more influence over the diff, as discussed in #1120.)

I agree that the expected output you provided in your example is more useful than the current output. Chai could achieve this by sorting the expected and actual arrays in the case of unordered members assertions. Unfortunately, with the way Chai currently works, there'd be a performance penalty to implementing this change right now, because the expected and actual objects are constructed even in the case of a passing test. In a future version of Chai, we'd only need to perform the sorting in the case of a failed assertion. (Or, better yet, generate the diff ourselves, or at least provide information to the test runner on how to do it.)

Given these current issues & limitations in Chai related to diffing, I'm not sure the value of this change is high enough to justify the cost.

@keithamus
Copy link
Member

Hey @LokiMidgard thanks for this issue!

We'll be spending a lot of time with the new version of chai to address issues like this. I think right now this issue will likely be swept up with a bunch of new refactoring work on our inspection utilities.

I think we can close this as it'll be implicitly resolved by a new major release of loupe which will be a major rewrite.

@vassudanagunta
Copy link

@keithamus, @meeber,

It's been 6 years, and it looks like the aforementioned work did not end up addressing this. Can this be re-opened? Or should I create a new issue?

@keithamus
Copy link
Member

Sure please file a new issue with a concrete reproduction. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants