-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[Bug]: toMatchObject output does not show class getter value #13397
Comments
I was trying to create a quick fix, but it seems quite difficult to cover all bases without editing things here and there. You can see my primitive first attempt here: main...Rochet2:jest:tomatchobject-output The more I delve into this the more I feel like parts or the core of the diffing logic should be rewritten. it("Objects differ, but test unexpectedly passes", () => {
const a = new Set([1,2,3]);
const b = new Set([1,2,3]);
b.x = 5 // ignored
expect(a).toMatchObject(b);
});
it('Says circular reference is missing, because unexpectedly inherited classes are ignored', () => {
const a = {}; // ignored
a.ref = a; // ignored
const b = Object.create(a);
b.other = 'child';
const matcher = {other: 'child'};
matcher.ref = matcher;
expect(b).toMatchObject(matcher);
}); I was not able to set up debugging properly yet while testing around. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Version
29.1.2
Steps to reproduce
npm install
npm test
Expected behavior
When expectation does not match actual, the output should show getter value for a class the same way it does for a regular object with a getter
Actual behavior
When expectation does not match actual, the output does not show class getter value at all which renders output less useful
Additional context
Image of the results of
npm test
: ImageThis issue shows up when tests fail that expect on supertest responses. Supertest responses are classes that hold the body behind a getter. This means that when the test fails it will be difficult to debug as the entire body shows up missing. Here is a small example:
It appears that this part may be at fault.
Object.keys()
does not return the class getter, so the getter is never matched in this part of the code.https://github.com/facebook/jest/blob/3c31dd619e8c022cde53f40fa12ea2a67f4752ce/packages/expect-utils/src/utils.ts#L127-L133
This issue seems similar to:
toHaveBeenCalledWith
objectContaining
issue after patch update 26.6.1 #10716It appears that fixing this may partially affect/fix this:
Environment
The text was updated successfully, but these errors were encountered: