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

Feature request: add option to skip nonmatching properties when snapshot does not match #5907

Closed
capaj opened this issue Apr 1, 2018 · 2 comments

Comments

@capaj
Copy link
Contributor

capaj commented Apr 1, 2018

I often test object from the database-like:

{
    "campaign_banner_id": null,
    "campaign_email_id": null,
    "campaign_id": 1,
    "is_last_message": null,
    "notification_id": null,
    "notification_processed_id": null,
    "type": "join",
    "user_id": 1,
    "timestamp": "2018-04-01T14:45:54.555Z"
  }

they are usually bigger and not just flat and small like this, but this will suffice as example.
Now when I have a snapshot assertion it will fail because the timestamp prop is different each time the test is run. This is in some cases solvable by mocking out time, but often I am doing an integration test where the time would have to be mocked on my system level. I am not aware of any reliable way to mock a time on system level-changing it won't help because test execution takes some time and this time is always different.
So my only option currently is to use something like

import omitDeep from 'omit-deep-lodash'
expect(omitDeep(myObject, ['timestamp'])).toMatchSnapshot()

this works, but it makes it a little tedious to write these assertions. Couldn't we store this information into the snapshots themselves? Like a list of paths in the snapshots that should be skipped when comparing?
Ideally jest should be able to write this upon a snapshot failuire where currently I can press u to update so I would press s or p to skip failed properties.
It should also work for properties which are deeper than on the root of the compared object.

@SimenB
Copy link
Member

SimenB commented Apr 2, 2018

IMO this functionality is covered by #5847.

Couldn't we store this information into the snapshots themselves?

That's harder as we don't really store any information there - it's just a serialization.

@SimenB SimenB closed this as completed Apr 2, 2018
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants