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
I am using snapshottest on a project that has a level of randomization to test interdependent relationships. It would be helpful if snapshottest could validate the schema of the test result instead of the full text.
This could be achieved by adding a snapshot.assert_schema_match(format='json', test_result) or something similar.
The text was updated successfully, but these errors were encountered:
BadAsstronaut
changed the title
Feature Request:
Feature Request: Snapshot Schema Validation
Mar 25, 2018
I like the idea of custom comparators. It could also address the various "ignore some fields" needs (#21, #32, #102, et al).
JavaScript's jest-snapshot (the inspiration for this package) handles this problem through "asymmetric property matchers". You effectively declare a schema inline in your snapshot test assertion, by placing their any matchers within objects, arrays, and constants that define the (partial) expected shape. (Anything not specified by an any must match the snapshot exactly.)
callee is a Python package that implements something similar, intended for use with mock. I haven't tried it myself yet (just discovered it today), but it looks useful. I wonder how much work it would take to get callee's matchers working with snapshottest? Something like...
snapshot.assert_match(my_api_response, match={
"id": callee.Integer(),
"history": { # nesting allowed..."created_at": callee.InstanceOf(datetime),
"edit_timestamps": callee.List(callee.Integer()),
},
# everything else in my_api_response# must exactly match the snapshot
})
Hi, thank you for creating this library!
I am using snapshottest on a project that has a level of randomization to test interdependent relationships. It would be helpful if snapshottest could validate the schema of the test result instead of the full text.
This could be achieved by adding a snapshot.assert_schema_match(format='json', test_result) or something similar.
The text was updated successfully, but these errors were encountered: