-
-
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
Snapshotting Arrays with Matchers #9079
Comments
cc @pedrottimark noticed something when dealing with propertyMatchers in #9049? |
Sadly, snapshot testing with property matchers is unusable with arrays at the moment. |
This also tripped me up, and I've confirmed it is still an issue on A simple way to replicate the error: expect([
{ id: 1, createdAt: new Date() },
{ id: 2, createdAt: new Date() },
]).toMatchSnapshot([
{ createdAt: new Date() },
{ createdAt: new Date() },
]); The snapshot I'd expect: Object {
"0": Object {
"createdAt": Any<Date>,
"id": 1,
},
"1": Object {
"createdAt": Any<Date>,
"id": 2,
},
} The snapshot I get: Object {
"0": Object {
"createdAt": 2020-08-06T23:54:53.133Z,
"id": 1,
},
"1": Object {
"createdAt": 2020-08-06T23:54:53.133Z,
"id": 2,
},
} The object wrapping approach @j suggested has worked: expect({ data: [
{ id: 1, createdAt: new Date() },
{ id: 2, createdAt: new Date() },
]}).toMatchSnapshot({ data: [
{ createdAt: expect.any(Date) },
{ createdAt: expect.any(Date) },
]}); Produces a snapshot of: Object {
"data": Array [
Object {
"createdAt": Any<Date>,
"id": 1,
},
Object {
"createdAt": Any<Date>,
"id": 2,
},
],
} |
This comment has been minimized.
This comment has been minimized.
Just ran into this issue, would love to see a fix. |
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
Would love to see this feature implemented, just wanted to bump to keep the issue from getting stale |
Any update? |
Any updates on this? |
Encountered this issue today. Bummed that it hasn't been fixed in 5 years. |
🐛 Bug Report
Creating a snapshot with array + matchers is not possible without wrapping array into an object.
To Reproduce
Expected behavior
Actual behavior
I'm able to get by by taking my result and placing it in an object then doing the snapshot, but I feel like I should be able to snapshot an actual array with matchers.
The text was updated successfully, but these errors were encountered: