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

Snapshot failing even though nothing changed #29

Open
rodoabad opened this issue Feb 26, 2020 · 5 comments
Open

Snapshot failing even though nothing changed #29

rodoabad opened this issue Feb 26, 2020 · 5 comments

Comments

@rodoabad
Copy link

  {
    "businessContactSelected": false,
    "machineConfigHasChanged": false,
    "machineHeaderHasChanged": false,
    "cancellable": false,
    "editable": false,
    "selected": false,
    "machineSelected": false,
    "isFeatured": false,
    "isBranch": false,
    "failedApplySelections": false,
    "invalidConfiguration": false,
    "purchaseOrderNumber": "",
    "sapOrderNumber": "",
    "isIsgAgreementAccepted": false,
    "isBranchStock": false,
    "isAttachment": false,
    "referenceComment": "",
    "linkType": "",
    "featured": false,
    "branch": false,
    "branchStock": false
  }
]

Missing content at line 21:
  ["    "branch": false,"]

Extra content at line 23:
  ["    "branch": false,"]

How is this possible that test is failing?

@rodoabad
Copy link
Author

Another run (this time in CI).

  {
    "businessContactSelected": false,
    "machineConfigHasChanged": false,
    "machineHeaderHasChanged": false,
    "cancellable": false,
    "editable": false,
    "selected": false,
    "machineSelected": false,
    "isFeatured": false,
    "isBranch": false,
    "failedApplySelections": false,
    "invalidConfiguration": false,
    "purchaseOrderNumber": "",
    "sapOrderNumber": "",
    "isIsgAgreementAccepted": false,
    "isBranchStock": false,
    "isAttachment": false,
    "referenceComment": "",
    "linkType": "",
    "branch": false,
    "featured": false,
    "branchStock": false
  }
]

Missing content at line 21:
  ["    "featured": false,"]

Extra content at line 23:
  ["    "featured": false,"]

@rodoabad
Copy link
Author

How can the order change?

@grimsa
Copy link
Collaborator

grimsa commented Feb 28, 2020

@rodoabad How is this JSON produced? There might be a difference in iteration order somewhere.

I've seen similar issues when we were doing something like this:

toJson(
  Map.of(
    key1, value1,
    key2, value2
  )
);

Turns out Map.of entry iteration order is undefined and it varies between JVM versions/implementations.
Same could probably be true for hash-based collections.

@rodoabad
Copy link
Author

@grimsa basically...

expect(new Foo())toMatchSnapshot();

@rodoabad
Copy link
Author

Might be a good idea to sort alphabetically before saving the snapshot.

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

No branches or pull requests

2 participants