Skip to content

Commit 1214b30

Browse files
authored
test: Fix "couldn't locate all inline snapshots" (#21205)
1 parent 1a02d27 commit 1214b30

File tree

8 files changed

+68
-183
lines changed

8 files changed

+68
-183
lines changed

packages/react-devtools-shared/src/__tests__/inspectedElement-test.js

+36-89
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ describe('InspectedElement', () => {
136136
return inspectedElement;
137137
}
138138

139-
it('should inspect the currently selected element', async done => {
139+
it('should inspect the currently selected element', async () => {
140140
const Example = () => {
141141
const [count] = React.useState(1);
142142
return count;
@@ -170,11 +170,9 @@ describe('InspectedElement', () => {
170170
"state": null,
171171
}
172172
`);
173-
174-
done();
175173
});
176174

177-
it('should have hasLegacyContext flag set to either "true" or "false" depending on which context API is used.', async done => {
175+
it('should have hasLegacyContext flag set to either "true" or "false" depending on which context API is used.', async () => {
178176
const contextData = {
179177
bool: true,
180178
};
@@ -270,10 +268,9 @@ describe('InspectedElement', () => {
270268
expect(inspectedElement.context).not.toBe(null);
271269
expect(inspectedElement.hasLegacyContext).toBe(shouldHaveLegacyContext);
272270
}
273-
done();
274271
});
275272

276-
it('should poll for updates for the currently selected element', async done => {
273+
it('should poll for updates for the currently selected element', async () => {
277274
const Example = () => null;
278275

279276
const container = document.createElement('div');
@@ -312,11 +309,9 @@ describe('InspectedElement', () => {
312309
"b": "def",
313310
}
314311
`);
315-
316-
done();
317312
});
318313

319-
it('should not re-render a function with hooks if it did not update since it was last inspected', async done => {
314+
it('should not re-render a function with hooks if it did not update since it was last inspected', async () => {
320315
let targetRenderCount = 0;
321316

322317
const Wrapper = ({children}) => children;
@@ -377,11 +372,9 @@ describe('InspectedElement', () => {
377372
"b": "def",
378373
}
379374
`);
380-
381-
done();
382375
});
383376

384-
it('should temporarily disable console logging when re-running a component to inspect its hooks', async done => {
377+
it('should temporarily disable console logging when re-running a component to inspect its hooks', async () => {
385378
let targetRenderCount = 0;
386379

387380
jest.spyOn(console, 'error').mockImplementation(() => {});
@@ -422,11 +415,9 @@ describe('InspectedElement', () => {
422415
expect(console.info).toHaveBeenCalledTimes(1);
423416
expect(console.log).toHaveBeenCalledTimes(1);
424417
expect(console.warn).toHaveBeenCalledTimes(1);
425-
426-
done();
427418
});
428419

429-
it('should support simple data types', async done => {
420+
it('should support simple data types', async () => {
430421
const Example = () => null;
431422

432423
const container = document.createElement('div');
@@ -463,11 +454,9 @@ describe('InspectedElement', () => {
463454
expect(props.nan).toBeNaN();
464455
expect(props.value_null).toBeNull();
465456
expect(props.value_undefined).toBeUndefined();
466-
467-
done();
468457
});
469458

470-
it('should support complex data types', async done => {
459+
it('should support complex data types', async () => {
471460
const Immutable = require('immutable');
472461

473462
const Example = () => null;
@@ -719,11 +708,9 @@ describe('InspectedElement', () => {
719708
expect(typed_array[2]).toBe(0);
720709
expect(typed_array[meta.preview_long]).toBe('Int8Array(3) [100, -100, 0]');
721710
expect(typed_array[meta.preview_short]).toBe('Int8Array(3)');
722-
723-
done();
724711
});
725712

726-
it('should not consume iterables while inspecting', async done => {
713+
it('should not consume iterables while inspecting', async () => {
727714
const Example = () => null;
728715

729716
function* generator() {
@@ -745,11 +732,9 @@ describe('InspectedElement', () => {
745732
expect(prop[meta.type]).toBe('opaque_iterator');
746733
expect(prop[meta.preview_long]).toBe('Generator');
747734
expect(prop[meta.preview_short]).toBe('Generator');
748-
749-
done();
750735
});
751736

752-
it('should support objects with no prototype', async done => {
737+
it('should support objects with no prototype', async () => {
753738
const Example = () => null;
754739

755740
const object = Object.create(null);
@@ -772,11 +757,9 @@ describe('InspectedElement', () => {
772757
},
773758
}
774759
`);
775-
776-
done();
777760
});
778761

779-
it('should support objects with overridden hasOwnProperty', async done => {
762+
it('should support objects with overridden hasOwnProperty', async () => {
780763
const Example = () => null;
781764

782765
const object = {
@@ -795,11 +778,9 @@ describe('InspectedElement', () => {
795778
// Our snapshot serializer relies on hasOwnProperty() for feature detection.
796779
expect(inspectedElement.props.object.name).toBe('blah');
797780
expect(inspectedElement.props.object.hasOwnProperty).toBe(true);
798-
799-
done();
800781
});
801782

802-
it('should support custom objects with enumerable properties and getters', async done => {
783+
it('should support custom objects with enumerable properties and getters', async () => {
803784
class CustomData {
804785
_number = 42;
805786
get number() {
@@ -833,11 +814,9 @@ describe('InspectedElement', () => {
833814
},
834815
}
835816
`);
836-
837-
done();
838817
});
839818

840-
it('should support objects with with inherited keys', async done => {
819+
it('should support objects with with inherited keys', async () => {
841820
const Example = () => null;
842821

843822
const base = Object.create(Object.prototype, {
@@ -917,11 +896,9 @@ describe('InspectedElement', () => {
917896
},
918897
}
919898
`);
920-
921-
done();
922899
});
923900

924-
it('should allow component prop value and value`s prototype has same name params.', async done => {
901+
it('should allow component prop value and value`s prototype has same name params.', async () => {
925902
const testData = Object.create(
926903
{
927904
a: undefined,
@@ -973,11 +950,9 @@ describe('InspectedElement', () => {
973950
},
974951
}
975952
`);
976-
977-
done();
978953
});
979954

980-
it('should not dehydrate nested values until explicitly requested', async done => {
955+
it('should not dehydrate nested values until explicitly requested', async () => {
981956
const Example = () => {
982957
const [state] = React.useState({
983958
foo: {
@@ -1140,11 +1115,9 @@ describe('InspectedElement', () => {
11401115
},
11411116
]
11421117
`);
1143-
1144-
done();
11451118
});
11461119

1147-
it('should dehydrate complex nested values when requested', async done => {
1120+
it('should dehydrate complex nested values when requested', async () => {
11481121
const Example = () => null;
11491122

11501123
const container = document.createElement('div');
@@ -1208,11 +1181,9 @@ describe('InspectedElement', () => {
12081181
},
12091182
}
12101183
`);
1211-
1212-
done();
12131184
});
12141185

1215-
it('should include updates for nested values that were previously hydrated', async done => {
1186+
it('should include updates for nested values that were previously hydrated', async () => {
12161187
const Example = () => null;
12171188

12181189
const container = document.createElement('div');
@@ -1373,11 +1344,9 @@ describe('InspectedElement', () => {
13731344
},
13741345
}
13751346
`);
1376-
1377-
done();
13781347
});
13791348

1380-
it('should return a full update if a path is inspected for an object that has other pending changes', async done => {
1349+
it('should return a full update if a path is inspected for an object that has other pending changes', async () => {
13811350
const Example = () => null;
13821351

13831352
const container = document.createElement('div');
@@ -1510,11 +1479,9 @@ describe('InspectedElement', () => {
15101479
},
15111480
}
15121481
`);
1513-
1514-
done();
15151482
});
15161483

1517-
it('should not tear if hydration is requested after an update', async done => {
1484+
it('should not tear if hydration is requested after an update', async () => {
15181485
const Example = () => null;
15191486

15201487
const container = document.createElement('div');
@@ -1598,11 +1565,9 @@ describe('InspectedElement', () => {
15981565
},
15991566
}
16001567
`);
1601-
1602-
done();
16031568
});
16041569

1605-
it('should inspect hooks for components that only use context', async done => {
1570+
it('should inspect hooks for components that only use context', async () => {
16061571
const Context = React.createContext(true);
16071572
const Example = () => {
16081573
const value = React.useContext(Context);
@@ -1637,11 +1602,9 @@ describe('InspectedElement', () => {
16371602
"state": null,
16381603
}
16391604
`);
1640-
1641-
done();
16421605
});
16431606

1644-
it('should enable inspected values to be stored as global variables', async done => {
1607+
it('should enable inspected values to be stored as global variables', async () => {
16451608
const Example = () => null;
16461609

16471610
const nestedObject = {
@@ -1698,11 +1661,9 @@ describe('InspectedElement', () => {
16981661
jest.runOnlyPendingTimers();
16991662
expect(console.log).toHaveBeenCalledWith('$reactTemp1');
17001663
expect(global.$reactTemp1).toBe(nestedObject.a.b);
1701-
1702-
done();
17031664
});
17041665

1705-
it('should enable inspected values to be copied to the clipboard', async done => {
1666+
it('should enable inspected values to be copied to the clipboard', async () => {
17061667
const Example = () => null;
17071668

17081669
const nestedObject = {
@@ -1761,11 +1722,9 @@ describe('InspectedElement', () => {
17611722
expect(global.mockClipboardCopy).toHaveBeenCalledWith(
17621723
JSON.stringify(nestedObject.a.b),
17631724
);
1764-
1765-
done();
17661725
});
17671726

1768-
it('should enable complex values to be copied to the clipboard', async done => {
1727+
it('should enable complex values to be copied to the clipboard', async () => {
17691728
const Immutable = require('immutable');
17701729

17711730
const Example = () => null;
@@ -1856,11 +1815,9 @@ describe('InspectedElement', () => {
18561815
expect(global.mockClipboardCopy).toHaveBeenCalledWith(
18571816
JSON.stringify({0: 100, 1: -100, 2: 0}),
18581817
);
1859-
1860-
done();
18611818
});
18621819

1863-
it('should display complex values of useDebugValue', async done => {
1820+
it('should display complex values of useDebugValue', async () => {
18641821
const container = document.createElement('div');
18651822

18661823
function useDebuggableHook() {
@@ -1899,12 +1856,10 @@ describe('InspectedElement', () => {
18991856
},
19001857
]
19011858
`);
1902-
1903-
done();
19041859
});
19051860

19061861
describe('$r', () => {
1907-
it('should support function components', async done => {
1862+
it('should support function components', async () => {
19081863
const Example = () => {
19091864
const [count] = React.useState(1);
19101865
return count;
@@ -1935,11 +1890,9 @@ describe('InspectedElement', () => {
19351890
"type": [Function],
19361891
}
19371892
`);
1938-
1939-
done();
19401893
});
19411894

1942-
it('should support memoized function components', async done => {
1895+
it('should support memoized function components', async () => {
19431896
const Example = React.memo(function Example(props) {
19441897
const [count] = React.useState(1);
19451898
return count;
@@ -1970,11 +1923,9 @@ describe('InspectedElement', () => {
19701923
"type": [Function],
19711924
}
19721925
`);
1973-
1974-
done();
19751926
});
19761927

1977-
it('should support forward refs', async done => {
1928+
it('should support forward refs', async () => {
19781929
const Example = React.forwardRef(function Example(props, ref) {
19791930
const [count] = React.useState(1);
19801931
return count;
@@ -2005,11 +1956,9 @@ describe('InspectedElement', () => {
20051956
"type": [Function],
20061957
}
20071958
`);
2008-
2009-
done();
20101959
});
20111960

2012-
it('should support class components', async done => {
1961+
it('should support class components', async () => {
20131962
class Example extends React.Component {
20141963
state = {
20151964
count: 0,
@@ -2027,18 +1976,16 @@ describe('InspectedElement', () => {
20271976
await inspectElementAtIndex(0);
20281977

20291978
expect(global.$r.props).toMatchInlineSnapshot(`
2030-
Object {
2031-
"a": 1,
2032-
"b": "abc",
2033-
}
2034-
`);
1979+
Object {
1980+
"a": 1,
1981+
"b": "abc",
1982+
}
1983+
`);
20351984
expect(global.$r.state).toMatchInlineSnapshot(`
2036-
Object {
2037-
"count": 0,
2038-
}
2039-
`);
2040-
2041-
done();
1985+
Object {
1986+
"count": 0,
1987+
}
1988+
`);
20421989
});
20431990
});
20441991

0 commit comments

Comments
 (0)