-
Notifications
You must be signed in to change notification settings - Fork 37
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
Enable paths for matchers to declare all elements of nested list #423
Comments
You can do this with a custom matcher. You can model it after the built in matcher here: https://github.com/tophat/syrupy/blob/93fa3d664e02e9ed7945988c653c5c5c49dd7f71/src/syrupy/matchers.py#L39 Obviously this isn't ideal and I agree having this as a built in feature is preferable. I don't believe the assert actual === snapshot(matcher=path_type({
r'data\..*\.dateCreated': (datetime,)
}, regex=True)) Thoughts? Feel free to put up a PR, contributors are always welcome. Otherwise I can take a look at some point today. |
There is also the Sample docs for this is in the readme#matcher-path_type. Example: assert actual === snapshot(matcher=path_type(types=(datetime, uuid)) Also, if it's applicable to your use-case there's also the filters which you can use to exclude all props matching a name you expect to be non-deterministic. Useful if the size of the snapshot will be especially large. Sample docs for this is in the readme#exclude-props. Example: assert actual == snapshot(exclude=props("dateCreated", "uuid")) |
🎉 This issue has been resolved in version 1.4.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Is your feature request related to a problem? Please describe.
I want to use Syrupy when testing API response bodies. I have nested lists of objects inside my payload. There are values that are returned as part of the nested objects that are not static (eg, created dates, uuids, etc). I am using the
path_type
matcher to access the nth element of an object, eg"data.0.dateCreated": (str,)
. I would like to do some tests with larger amounts of elements in the nested list. I cannot see a way to replace the previous with something that operates on all elements of the list.Describe the solution you'd like
It would be nice to be able to do some thing like
"data.*.dateCreated": (str,)
. I would expect this to operate on all the elements of the list and replace the date created with the<class str>
value.Describe alternatives you've considered
The way I can see to do this right now is to write it out by hand, which is not particularly fun and prone to error. I could not see anything obvious that would let me do what I am looking for.
Additional context
I was just looking for a way to open an issue to ask if this was doable, but there was no question option. So I made it a feature
request. If this is something that is doable then I have totally missed where it is described in the docs.
The text was updated successfully, but these errors were encountered: