bradleyjkemp / cupaloy

Simple Go snapshot testing
MIT License
308 stars 26 forks source link

Feature request: support Property Matchers like Jest #75

Open cdignam-segment opened 2 years ago

cdignam-segment commented 2 years ago

Jest has a great feature for matching specific types for fields: https://jestjs.io/docs/snapshot-testing#property-matchers

It would be great if this library also support this.

bradleyjkemp commented 2 years ago

Hey 👋🏻

Unfortunately, this sounds a pretty tricky feature to implement in this library. Whereas jest has you specify your snapshots in code, cupaloy does the snapshotting for you and saves them to disk.

The closest library I know of that might help is https://github.com/sebdah/goldie which lets you have Go templates as your snapshots and interpolate values into them at test-time: https://github.com/sebdah/goldie#assertions-using-templates

In contast, cupaloy is very simple and so requires that the datastructure you pass in already has any non-deterministic/non-repeatable data (like timestamps, etc.) mocked out with static values