-
Notifications
You must be signed in to change notification settings - Fork 28
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
Allow exclusion of fields #68
Comments
Hey @colindooley11, Sorry about the super late reply. I've had this kind of a feature in mind for a while but didn't feel like it needed to be Snapper as like you mentioned the user can easily pre-process their own object.
This is what I originally had in mind but I decided to hold off on it for now for two reasons.
|
1 |
I have come back to this library after a while and I swear when I first encountered it back in October 2019, prompted by learning about jest in when learning Vue. Js, there was a capability to exclude (or ignore the value of) certain fields from the snapshot check.
I can't find any notion of this.
I think it would be a useful feature to be able to exclude fields which change.
For example. And the wording and specifics of my method is to illustrate the point and is not that important.
[Fact]
public void MyTest()
{
var myUser = _userService.CreateUser(new User() );
myUser.ShouldMatchSnapshot()
.Exclude((user) => user.Id)
}
I think if you were able to load the snapshot and apply the exclusion and apply the exclusion to the
In memory object and then compare, this might not be too hard to achieve. The typing would be provided by the type available coming into the first extension method and then maybe simply using anonymous types or using reflection you could skip over the field to exclude. I think it might get harder with nested properties though.
EDIT: actually the concept of exclusion Is probably the wrong
Or different thing to what I am after it's more like ignoring the value of a field or defaulting a a changeable field to a fixed value....
I guess a workaround to this would be to do the exclusion/defaulting on the model we want the snapshot of and Then create the snapshot.
So do what I said about exclusion/ignore but in place and then create the snapshot.. I could hide this in my own set of wrapper methods for the time being I guess.
The text was updated successfully, but these errors were encountered: