Skip to content

Commit dd4911b

Browse files
committed
Current behavior
1 parent ae5c2f8 commit dd4911b

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

packages/react-debug-tools/src/__tests__/ReactHooksInspection-test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,53 @@ describe('ReactHooksInspection', () => {
720720
);
721721
});
722722

723+
it('should inspect use() calls in anonymous loops', () => {
724+
function Foo({entries}) {
725+
const values = Object.fromEntries(
726+
Object.entries(entries).map(([key, value]) => {
727+
return [key, React.use(value)];
728+
}),
729+
);
730+
return <div>{values}</div>;
731+
}
732+
const tree = ReactDebugTools.inspectHooks(Foo, {
733+
entries: {one: Promise.resolve('one'), two: Promise.resolve('two')},
734+
});
735+
const results = normalizeSourceLoc(tree);
736+
expect(results).toHaveLength(1);
737+
expect(results[0]).toMatchInlineSnapshot(`
738+
{
739+
"debugInfo": null,
740+
"hookSource": {
741+
"columnNumber": 0,
742+
"fileName": "**",
743+
"functionName": "Foo",
744+
"lineNumber": 0,
745+
},
746+
"id": null,
747+
"isStateEditable": false,
748+
"name": "",
749+
"subHooks": [
750+
{
751+
"debugInfo": null,
752+
"hookSource": {
753+
"columnNumber": 0,
754+
"fileName": "**",
755+
"functionName": undefined,
756+
"lineNumber": 0,
757+
},
758+
"id": null,
759+
"isStateEditable": false,
760+
"name": "Use",
761+
"subHooks": [],
762+
"value": Promise {},
763+
},
764+
],
765+
"value": undefined,
766+
}
767+
`);
768+
});
769+
723770
describe('useDebugValue', () => {
724771
it('should be ignored when called outside of a custom hook', () => {
725772
function Foo(props) {

0 commit comments

Comments
 (0)