-
Notifications
You must be signed in to change notification settings - Fork 28
Description
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.