You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reusing the same objects with property matchers results in unsuccessful validation of the object towards it.
To Reproduce
Steps to reproduce the behavior:
Create an object with matcher A: { createdAt: expect.any(String) }
Create a matcher B using the previous matcher under two different keys: { foo: timestampMatcher, bar: timestampMatcher }
Create a value that satisfies the matcher B, but has additional values for one one of the values for matcher A: { foo: { createdAt: "def" }, bar: { createdAt: "def", baz: "ab1" } }
Test expect(value).toMatchSnapshot(B);
Expected behavior
I expected to successfully create snapshots, because value satisfy the property matcher constrains.
Creating new matcher A for each property of B ({ foo: {...timestampMatcher}, bar: {...timestampMatcher} }) does not trigger the error and works as expected. (shown in MWE)
I tried to debug it and found out that it is caused by seenReferences "caching" in expect. Disabling this if block fixes the issue.
Alas I could not find a way to fix it without disabling the seenRefences feature.
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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
🐛 Bug Report
Reusing the same objects with property matchers results in unsuccessful validation of the object towards it.
To Reproduce
Steps to reproduce the behavior:
{ createdAt: expect.any(String) }
{ foo: timestampMatcher, bar: timestampMatcher }
{ foo: { createdAt: "def" }, bar: { createdAt: "def", baz: "ab1" } }
expect(value).toMatchSnapshot(B);
Expected behavior
I expected to successfully create snapshots, because value satisfy the property matcher constrains.
Instead I get the follwing error.
Debug info
Creating new matcher A for each property of B (
{ foo: {...timestampMatcher}, bar: {...timestampMatcher} }
) does not trigger the error and works as expected. (shown in MWE)I tried to debug it and found out that it is caused by
seenReferences
"caching" inexpect
. Disabling this if block fixes the issue.Alas I could not find a way to fix it without disabling the seenRefences feature.
Link to repl or repo (highly encouraged)
https://github.com/grissius/jest-bug-reuse-property-matchers
envinfo
The text was updated successfully, but these errors were encountered: