Skip to content

Commit

Permalink
replaceRevive tests: Stop using snapshot tests.
Browse files Browse the repository at this point in the history
As Greg points out [1], this isn't a best fit for snapshot tests. A
blog post [2] linked from a Jest doc says,

"""
The first thing that became clear to me while using snapshot testing
is that they’re not for everything. They are optimized for a
different case than normal assertion-based tests.

Classic assertion based tests are perfect for testing clearly
defined behavior that is expected to remain relatively stable.

Snapshot tests are great for testing less clearly defined behavior
that may change often.
"""

Which we think is basically right.

[1] zulip#4348 (comment)
[2] https://benmccormick.org/2016/09/19/testing-with-jest-snapshots-first-impressions/
  • Loading branch information
chrisbobbe committed May 10, 2021
1 parent 63602a6 commit 698b4de
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
23 changes: 0 additions & 23 deletions src/boot/__tests__/__snapshots__/replaceRevive-test.js.snap

This file was deleted.

25 changes: 19 additions & 6 deletions src/boot/__tests__/replaceRevive-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,29 @@ const data = {
},
};

const stringified = {};

Object.keys(data).forEach(key => {
stringified[key] = stringify(data[key]);
});
const stringified = {
list: '{"data":[1,2,"a",null],"__serializedType__":"ImmutableList"}',
map: '{"data":{"a":1,"b":2,"c":3,"d":4},"__serializedType__":"ImmutableMap"}',
mapWithTypeKey:
'{"data":{"__serializedType__":"Object","data":{"a":1},"__serializedType__value":{"__serializedType__":"Object","data":{"b":[2]},"__serializedType__value":{"c":[3]}}},"__serializedType__":"ImmutableMap"}',
mapNumKeys: '{"data":{"1":1,"2":2,"3":3,"4":4},"__serializedType__":"ImmutableMapNumKeys"}',
emptyMap: '{"data":{},"__serializedType__":"ImmutableMap"}',
zulipVersion: '{"data":"3.0.0","__serializedType__":"ZulipVersion"}',
url: '{"data":"https://chat.zulip.org/","__serializedType__":"URL"}',
gravatarURL:
'{"data":"https://secure.gravatar.com/avatar/3b01d0f626dc6944ed45dbe6c86d3e30?d=identicon","__serializedType__":"GravatarURL"}',
uploadedAvatarURL:
'{"data":"https://zulip.example.org/user_avatars/2/e35cdbc4771c5e4b94e705bf6ff7cca7fa1efcae.png?x=x&version=2","__serializedType__":"UploadedAvatarURL"}',
fallbackAvatarURL:
'{"data":"https://zulip.example.org/avatar/1","__serializedType__":"FallbackAvatarURL"}',
plainObjectWithTypeKey:
'{"__serializedType__":"Object","data":{"a":1},"__serializedType__value":{"__serializedType__":"Object","data":{"b":[2]},"__serializedType__value":{"c":[3]}}}',
};

describe('Stringify', () => {
Object.keys(data).forEach(key => {
it(key, () => {
expect(stringified[key]).toMatchSnapshot();
expect(stringify(data[key])).toEqual(stringified[key]);
});
});

Expand Down

0 comments on commit 698b4de

Please sign in to comment.