pointfreeco / swift-snapshot-testing

📸 Delightful Swift snapshot testing.
https://www.pointfree.co/episodes/ep41-a-tour-of-snapshot-testing
MIT License
3.68k stars 556 forks source link

Snapshots tests fail when Json returns in different order, #806

Closed jambudi closed 8 months ago

jambudi commented 8 months ago

How do we resolve the problem when JSON returns in different orders all the time?

Screenshot 2023-11-08 at 4 07 38 PM

mbrandonw commented 8 months ago

Hi @jambudi, the .curl snapshot strategy does not have any awareness of JSON bodies vs HTTP form bodies vs any other kind of body. All it sees is raw data that is encoded to a string.

As such there is nothing the strategy can do to stabilize the data format. Instead, the code producing the JSON string (somewhere in your code) should be responsible for outputting sorted JSON during tests.

As this is not an issue with the library I am going to convert this to a discussion.