Skip to content
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

Open
colindooley11 opened this issue Jun 17, 2020 · 2 comments
Open

Allow exclusion of fields #68

colindooley11 opened this issue Jun 17, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@colindooley11
Copy link

colindooley11 commented Jun 17, 2020

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.

@colindooley11 colindooley11 added the enhancement New feature or request label Jun 17, 2020
@colindooley11 colindooley11 reopened this Jun 17, 2020
@theramis
Copy link
Owner

theramis commented Jan 11, 2021

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.
I saw the PR you made #78 and the implementation is quite separate from Snapper.

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....

This is what I originally had in mind but I decided to hold off on it for now for two reasons.

  1. I haven't seen enough demand for this feature
  2. I would like Snapper to encourage people to make deterministic tests. If there are parts of the snapshot changing, it violates that and can give a false sense of security to ones tests.

@gogulsekar
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants