Skip to content

Commit d3b923b

Browse files
committed
Fix date mismatch
1 parent 3f690b4 commit d3b923b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

packages/react-devtools-shared/src/__tests__/dehydratedValueSerializer.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ export function test(maybeDehydratedValue) {
1818
);
1919
}
2020

21+
function serializeDehydratedValuePreview(preview) {
22+
const date = new Date(preview);
23+
const isDatePreview = !Number.isNaN(date.valueOf());
24+
if (isDatePreview) {
25+
// The preview is just `String(date)` which formats the date in the local timezone.
26+
// This results in a snapshot mismatch between tests run in e.g. GMT and ET
27+
// 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').
28+
return date.toISOString();
29+
}
30+
return preview;
31+
}
32+
2133
// print() is part of Jest's serializer API
2234
export function print(dehydratedValue, serialize, indent) {
2335
const {meta} = require('react-devtools-shared/src/hydration');
@@ -27,11 +39,11 @@ export function print(dehydratedValue, serialize, indent) {
2739
'Dehydrated {\n' +
2840
paddingLeft +
2941
' "preview_short": ' +
30-
dehydratedValue[meta.preview_short] +
42+
serializeDehydratedValuePreview(dehydratedValue[meta.preview_short]) +
3143
',\n' +
3244
paddingLeft +
3345
' "preview_long": ' +
34-
dehydratedValue[meta.preview_long] +
46+
serializeDehydratedValuePreview(dehydratedValue[meta.preview_long]) +
3547
',\n' +
3648
paddingLeft +
3749
'}'

packages/react-devtools-shared/src/__tests__/legacy/inspectElement-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ describe('InspectedElementContext', () => {
241241
"preview_long": DataView(3),
242242
},
243243
"date": Dehydrated {
244-
"preview_short": Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time),
245-
"preview_long": Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time),
244+
"preview_short": 1970-01-01T00:00:00.000Z,
245+
"preview_long": 1970-01-01T00:00:00.000Z,
246246
},
247247
"fn": Dehydrated {
248248
"preview_short": ƒ exampleFunction() {},

0 commit comments

Comments
 (0)