Snapshotting Arrays with Matchers
See original GitHub issue🐛 Bug Report
Creating a snapshot with array + matchers is not possible without wrapping array into an object.
To Reproduce
expect(['foo']).toMatchInlineSnapshot([expect.any(String)]);
Expected behavior
expect(['foo']).toMatchInlineSnapshot([expect.any(String)], `
Array [
Any<String>,
]
`);
Actual behavior
expect(['foo']).toMatchInlineSnapshot([expect.any(String)], `
Object {
"0": "foo",
}
`);
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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:21
- Comments:8
Top Results From Across the Web
Using Jest property matchers on arrays of objects
To test an array of objects using property matchers use forEach to loop over the array and snapshot test each object individually:
Read more >Expect - Jest
arrayContaining(array); expect.assertions(number); expect. ... Here's a snapshot matcher that trims a string to store for a given length, .
Read more >Taking Advantage of Jest Matchers (Part 2) - Herding Lions
Snapshot Matchers Snapshot testing is one of Jest's signature features. It's been described in depth in many other places, including on this ......
Read more >Using Snapshots - Testing React Apps with Jest ... - Educative.io
Arrays can be snapshot tested using the toMatchSnapshot matcher in the same manner that we test an object. As an exercise, change the...
Read more >Matchers - typescript
Note that the type must be either an array or a tuple. ... This ensures that a value matches the most recent snapshot...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just ran into this issue, would love to see a fix.
Sadly, snapshot testing with property matchers is unusable with arrays at the moment.