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

toIncludeSameMembers output is hard to understand #639

Open
rluvaton opened this issue Aug 3, 2023 · 2 comments
Open

toIncludeSameMembers output is hard to understand #639

rluvaton opened this issue Aug 3, 2023 · 2 comments

Comments

@rluvaton
Copy link
Contributor

rluvaton commented Aug 3, 2023

Currently, if you have a test like this:

it('example', () => {
	const expected = Array.from({ length: 1000 }, (_, i) => ({
		i,
		value: 'expected'
	}));
	const actual = [...expected];
	const tmp = actual[200];
	actual[200] = actual[201];
	actual[201] = { ...tmp, value: 'hope you find me' };

	expect(actual).toIncludeSameMembers(expected);
});

You will get an error like this:
image

Error as text
   expect(received).toIncludeSameMembers(expected)

    Expected list to have the following members and no more:
      [{"i": 0, "value": "expected"}, {"i": 1, "value": "expected"}, {"i": 2, "value": "expected"}, {"i": 3, "value": "expected"}, {"i": 4, "value": "expected"}, {"i": 5, "value": "expected"}, {"i": 6, "value": "expected"}, {"i": 7, "value": "expected"}, {"i": 8, "value": "expected"}, {"i": 9, "value": "expected"}, ]
    Received:
      [{"i": 0, "value": "expected"}, {"i": 1, "value": "expected"}, {"i": 2, "value": "expected"}, {"i": 3, "value": "expected"}, {"i": 4, "value": "expected"}, {"i": 5, "value": "expected"}, {"i": 6, "value": "expected"}, {"i": 7, "value": "expected"}, {"i": 8, "value": "expected"}, {"i": 9, "value": "expected"}, ]

      410 |             actual[201] = { ...tmp, value: 'hope you find me' };
      411 |
    > 412 |             expect(actual).toIncludeSameMembers(expected);
          |                            ^
      413 |     });

which is very hard to understand so I would like to get something like this:

image

Error as text
    expect(received).toIncludeSameMembers(expected)

    - Expected  - 1
    + Received  + 1

    @@ -799,11 +799,11 @@
          "i": 199,
          "value": "expected",
        },
        Object {
          "i": 200,
    -     "value": "expected",
    +     "value": "hope you find me",
        },
        Object {
          "i": 201,
          "value": "expected",
        },

      410 |             actual[201] = { ...tmp, value: 'hope you find me' };
      411 |
    > 412 |             expect(actual).toIncludeSameMembers(expected);
          |                            ^
      413 |     });

version: 3.2.4

@rluvaton
Copy link
Contributor Author

Until and if the related PR gets merged I created an npm package with that matcher and the better output:
https://github.com/rluvaton/expect-matchers

@statico
Copy link

statico commented Dec 12, 2023

+100. Please address this.

@rluvaton Your repo works great, 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

2 participants