DEV Community

Discussion on: "I need to change this code, but it has no test"

Collapse
 
lexlohr profile image
Alex Lohr

You can actually write the snapshot itself as if it was code. The main advantage over toMatchObject(...) is that you can also use property matches like Any<Date> in there.

Thread Thread
 
nicoespeon profile image
Nicolas Carlo

Oh, I see! Indeed, that's an interesting way to do, thanks for sharing 😃

I wonder though: couldn't you use expect.any(…) to achieve the same, in your test code instead?

Thread Thread
 
lexlohr profile image
Alex Lohr

Not sure. Let me test later, have a bunch of meetings ahead now.

Thread Thread
 
lexlohr profile image
Alex Lohr

It actually seems to work.