Skip to content

Commit

Permalink
Fix date mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Jan 19, 2021
1 parent 3f690b4 commit d3b923b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ export function test(maybeDehydratedValue) {
);
}

function serializeDehydratedValuePreview(preview) {
const date = new Date(preview);
const isDatePreview = !Number.isNaN(date.valueOf());
if (isDatePreview) {
// The preview is just `String(date)` which formats the date in the local timezone.
// This results in a snapshot mismatch between tests run in e.g. GMT and ET
// WARNING: This does not guard against dates created with the default timezone i.e. the local timezone e.g. new Date('05 October 2011 14:48').
return date.toISOString();
}
return preview;
}

// print() is part of Jest's serializer API
export function print(dehydratedValue, serialize, indent) {
const {meta} = require('react-devtools-shared/src/hydration');
Expand All @@ -27,11 +39,11 @@ export function print(dehydratedValue, serialize, indent) {
'Dehydrated {\n' +
paddingLeft +
' "preview_short": ' +
dehydratedValue[meta.preview_short] +
serializeDehydratedValuePreview(dehydratedValue[meta.preview_short]) +
',\n' +
paddingLeft +
' "preview_long": ' +
dehydratedValue[meta.preview_long] +
serializeDehydratedValuePreview(dehydratedValue[meta.preview_long]) +
',\n' +
paddingLeft +
'}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ describe('InspectedElementContext', () => {
"preview_long": DataView(3),
},
"date": Dehydrated {
"preview_short": Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time),
"preview_long": Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time),
"preview_short": 1970-01-01T00:00:00.000Z,
"preview_long": 1970-01-01T00:00:00.000Z,
},
"fn": Dehydrated {
"preview_short": ƒ exampleFunction() {},
Expand Down

0 comments on commit d3b923b

Please sign in to comment.