diff --git a/packages/react-art/src/__tests__/ReactART-test.js b/packages/react-art/src/__tests__/ReactART-test.js index 26ec23da95e16..d3e9a74fa6929 100644 --- a/packages/react-art/src/__tests__/ReactART-test.js +++ b/packages/react-art/src/__tests__/ReactART-test.js @@ -24,13 +24,8 @@ import Wedge from 'react-art/Wedge'; // Isolate DOM renderer. jest.resetModules(); - const ReactDOMClient = require('react-dom/client'); -const act = require('internal-test-utils').act; - -// Isolate test renderer. -jest.resetModules(); -const ReactTestRenderer = require('react-test-renderer'); +let act = require('internal-test-utils').act; // Isolate the noop renderer jest.resetModules(); @@ -45,8 +40,16 @@ let TestComponent; let waitFor; let groupRef; +// let ReactDOMClient; +// let ReactTestRenderer +// let ReactNoop +// let Scheduler +// let act; + const Missing = {}; +// function setup() + function testDOMNodeStructure(domNode, expectedStructure) { expect(domNode).toBeDefined(); expect(domNode.nodeName).toBe(expectedStructure.nodeName); @@ -73,6 +76,7 @@ describe('ReactART', () => { let container; beforeEach(() => { + jest.resetModules(); container = document.createElement('div'); document.body.appendChild(container); @@ -449,85 +453,125 @@ describe('ReactART', () => { }); describe('ReactARTComponents', () => { - it('should generate a with props for drawing the Circle', () => { - const circle = ReactTestRenderer.create( - , - ); + let ReactTestRenderer; + beforeEach(() => { + jest.resetModules(); + ReactTestRenderer = require('react-test-renderer'); + act = require('internal-test-utils').act; + }); + + it('should generate a with props for drawing the Circle', async () => { + let circle; + await act(() => { + circle = ReactTestRenderer.create( + , + ); + }); expect(circle.toJSON()).toMatchSnapshot(); }); - it('should generate a with props for drawing the Rectangle', () => { - const rectangle = ReactTestRenderer.create( - , - ); + it('should generate a with props for drawing the Rectangle', async () => { + let rectangle; + await act(() => { + rectangle = ReactTestRenderer.create( + , + ); + }); expect(rectangle.toJSON()).toMatchSnapshot(); }); - it('should generate a with positive width when width prop is negative', () => { - const rectangle = ReactTestRenderer.create( - , - ); + it('should generate a with positive width when width prop is negative', async () => { + let rectangle; + await act(() => { + rectangle = ReactTestRenderer.create( + , + ); + }); expect(rectangle.toJSON()).toMatchSnapshot(); }); - it('should generate a with positive height when height prop is negative', () => { - const rectangle = ReactTestRenderer.create( - , - ); + it('should generate a with positive height when height prop is negative', async () => { + let rectangle; + await act(() => { + rectangle = ReactTestRenderer.create( + , + ); + }); expect(rectangle.toJSON()).toMatchSnapshot(); }); - it('should generate a with a radius property of 0 when top left radius prop is negative', () => { - const rectangle = ReactTestRenderer.create( - , - ); + it('should generate a with a radius property of 0 when top left radius prop is negative', async () => { + let rectangle; + await act(() => { + rectangle = ReactTestRenderer.create( + , + ); + }); expect(rectangle.toJSON()).toMatchSnapshot(); }); - it('should generate a with a radius property of 0 when top right radius prop is negative', () => { - const rectangle = ReactTestRenderer.create( - , - ); + it('should generate a with a radius property of 0 when top right radius prop is negative', async () => { + let rectangle; + await act(() => { + rectangle = ReactTestRenderer.create( + , + ); + }); expect(rectangle.toJSON()).toMatchSnapshot(); }); - it('should generate a with a radius property of 0 when bottom right radius prop is negative', () => { - const rectangle = ReactTestRenderer.create( - , - ); + it('should generate a with a radius property of 0 when bottom right radius prop is negative', async () => { + let rectangle; + await act(() => { + rectangle = ReactTestRenderer.create( + , + ); + }); expect(rectangle.toJSON()).toMatchSnapshot(); }); - it('should generate a with a radius property of 0 when bottom left radius prop is negative', () => { - const rectangle = ReactTestRenderer.create( - , - ); + it('should generate a with a radius property of 0 when bottom left radius prop is negative', async () => { + let rectangle; + await act(() => { + rectangle = ReactTestRenderer.create( + , + ); + }); expect(rectangle.toJSON()).toMatchSnapshot(); }); - it('should generate a where top radius is 0 if the sum of the top radius is greater than width', () => { - const rectangle = ReactTestRenderer.create( - , - ); + it('should generate a where top radius is 0 if the sum of the top radius is greater than width', async () => { + let rectangle; + await act(() => { + rectangle = ReactTestRenderer.create( + , + ); + }); expect(rectangle.toJSON()).toMatchSnapshot(); }); - it('should generate a with props for drawing the Wedge', () => { - const wedge = ReactTestRenderer.create( - , - ); + it('should generate a with props for drawing the Wedge', async () => { + let wedge; + await act(() => { + wedge = ReactTestRenderer.create( + , + ); + }); expect(wedge.toJSON()).toMatchSnapshot(); }); - it('should return null if startAngle equals to endAngle on Wedge', () => { - const wedge = ReactTestRenderer.create( - , - ); + it('should return null if startAngle equals to endAngle on Wedge', async () => { + let wedge; + await act(() => { + wedge = ReactTestRenderer.create( + , + ); + }); expect(wedge.toJSON()).toBeNull(); }); }); diff --git a/packages/react-debug-tools/src/__tests__/ReactDevToolsHooksIntegration-test.js b/packages/react-debug-tools/src/__tests__/ReactDevToolsHooksIntegration-test.js index 5da6b8de2a42e..318bc47cc15cb 100644 --- a/packages/react-debug-tools/src/__tests__/ReactDevToolsHooksIntegration-test.js +++ b/packages/react-debug-tools/src/__tests__/ReactDevToolsHooksIntegration-test.js @@ -55,7 +55,10 @@ describe('React hooks DevTools integration', () => { return
count:{count}
; } - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); expect(renderer.toJSON()).toEqual({ type: 'div', props: {}, @@ -107,7 +110,10 @@ describe('React hooks DevTools integration', () => { ); } - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); expect(renderer.toJSON()).toEqual({ type: 'div', props: {}, @@ -155,7 +161,10 @@ describe('React hooks DevTools integration', () => { return
count:{count}
; } - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); expect(renderer.toJSON()).toEqual({ type: 'div', props: {}, @@ -192,14 +201,16 @@ describe('React hooks DevTools integration', () => { function MyComponent() { return 'Done'; } - - const renderer = ReactTestRenderer.create( -
- - - -
, - ); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create( +
+ + + +
, + ); + }); const fiber = renderer.root._currentFiber().child; if (__DEV__) { // First render was locked @@ -254,7 +265,6 @@ describe('React hooks DevTools integration', () => { , - {unstable_isConcurrent: true}, ), ); diff --git a/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js b/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js index 1fc54ef0f9102..f8686e0732dcd 100644 --- a/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js +++ b/packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js @@ -51,7 +51,10 @@ describe('ReactHooksInspectionIntegration', () => { ); } - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); let childFiber = renderer.root.findByType(Foo)._currentFiber(); let tree = ReactDebugTools.inspectHooksOfFiber(childFiber); @@ -434,7 +437,7 @@ describe('ReactHooksInspectionIntegration', () => { "isStateEditable": false, "name": "Memo", "subHooks": [], - "value": "Ab", + "value": "AB", }, { "debugInfo": null, @@ -750,7 +753,7 @@ describe('ReactHooksInspectionIntegration', () => { "isStateEditable": false, "name": "Memo", "subHooks": [], - "value": "Ab", + "value": "AB", }, { "debugInfo": null, @@ -770,17 +773,20 @@ describe('ReactHooksInspectionIntegration', () => { `); }); - it('should inspect the value of the current provider in useContext', () => { + it('should inspect the value of the current provider in useContext', async () => { const MyContext = React.createContext('default'); function Foo(props) { const value = React.useContext(MyContext); return
{value}
; } - const renderer = ReactTestRenderer.create( - - - , - ); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create( + + + , + ); + }); const childFiber = renderer.root.findByType(Foo)._currentFiber(); const tree = ReactDebugTools.inspectHooksOfFiber(childFiber); expect(normalizeSourceLoc(tree)).toMatchInlineSnapshot(` @@ -803,14 +809,17 @@ describe('ReactHooksInspectionIntegration', () => { `); }); - it('should inspect forwardRef', () => { + it('should inspect forwardRef', async () => { const obj = function () {}; const Foo = React.forwardRef(function (props, ref) { React.useImperativeHandle(ref, () => obj); return
; }); const ref = React.createRef(); - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); const childFiber = renderer.root.findByType(Foo)._currentFiber(); const tree = ReactDebugTools.inspectHooksOfFiber(childFiber); @@ -834,13 +843,16 @@ describe('ReactHooksInspectionIntegration', () => { `); }); - it('should inspect memo', () => { + it('should inspect memo', async () => { function InnerFoo(props) { const [value] = React.useState('hello'); return
{value}
; } const Foo = React.memo(InnerFoo); - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); // TODO: Test renderer findByType is broken for memo. Have to search for the inner. const childFiber = renderer.root.findByType(InnerFoo)._currentFiber(); const tree = ReactDebugTools.inspectHooksOfFiber(childFiber); @@ -864,7 +876,7 @@ describe('ReactHooksInspectionIntegration', () => { `); }); - it('should inspect custom hooks', () => { + it('should inspect custom hooks', async () => { function useCustom() { const [value] = React.useState('hello'); return value; @@ -873,7 +885,10 @@ describe('ReactHooksInspectionIntegration', () => { const value = useCustom(); return
{value}
; } - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); const childFiber = renderer.root.findByType(Foo)._currentFiber(); const tree = ReactDebugTools.inspectHooksOfFiber(childFiber); expect(normalizeSourceLoc(tree)).toMatchInlineSnapshot(` @@ -911,14 +926,17 @@ describe('ReactHooksInspectionIntegration', () => { `); }); - it('should support composite useTransition hook', () => { + it('should support composite useTransition hook', async () => { function Foo(props) { React.useTransition(); const memoizedValue = React.useMemo(() => 'hello', []); React.useMemo(() => 'not used', []); return
{memoizedValue}
; } - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); const childFiber = renderer.root.findByType(Foo)._currentFiber(); const tree = ReactDebugTools.inspectHooksOfFiber(childFiber); expect(normalizeSourceLoc(tree)).toMatchInlineSnapshot(` @@ -969,14 +987,17 @@ describe('ReactHooksInspectionIntegration', () => { `); }); - it('should support useDeferredValue hook', () => { + it('should support useDeferredValue hook', async () => { function Foo(props) { React.useDeferredValue('abc'); const memoizedValue = React.useMemo(() => 1, []); React.useMemo(() => 2, []); return
{memoizedValue}
; } - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); const childFiber = renderer.root.findByType(Foo)._currentFiber(); const tree = ReactDebugTools.inspectHooksOfFiber(childFiber); expect(normalizeSourceLoc(tree)).toMatchInlineSnapshot(` @@ -1027,14 +1048,17 @@ describe('ReactHooksInspectionIntegration', () => { `); }); - it('should support useId hook', () => { + it('should support useId hook', async () => { function Foo(props) { const id = React.useId(); const [state] = React.useState('hello'); return
{state}
; } - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); const childFiber = renderer.root.findByType(Foo)._currentFiber(); const tree = ReactDebugTools.inspectHooksOfFiber(childFiber); @@ -1065,7 +1089,7 @@ describe('ReactHooksInspectionIntegration', () => { describe('useMemoCache', () => { // @gate enableUseMemoCacheHook - it('should not be inspectable', () => { + it('should not be inspectable', async () => { function Foo() { const $ = useMemoCache(1); let t0; @@ -1080,7 +1104,10 @@ describe('ReactHooksInspectionIntegration', () => { return t0; } - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); const childFiber = renderer.root.findByType(Foo)._currentFiber(); const tree = ReactDebugTools.inspectHooksOfFiber(childFiber); @@ -1088,7 +1115,7 @@ describe('ReactHooksInspectionIntegration', () => { }); // @gate enableUseMemoCacheHook - it('should work in combination with other hooks', () => { + it('should work in combination with other hooks', async () => { function useSomething() { const [something] = React.useState(null); const changeOtherSomething = React.useCallback(() => {}, [something]); @@ -1115,7 +1142,10 @@ describe('ReactHooksInspectionIntegration', () => { return t0; } - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); const childFiber = renderer.root.findByType(Foo)._currentFiber(); const tree = ReactDebugTools.inspectHooksOfFiber(childFiber); @@ -1124,7 +1154,7 @@ describe('ReactHooksInspectionIntegration', () => { }); describe('useDebugValue', () => { - it('should support inspectable values for multiple custom hooks', () => { + it('should support inspectable values for multiple custom hooks', async () => { function useLabeledValue(label) { const [value] = React.useState(label); React.useDebugValue(`custom label ${label}`); @@ -1141,7 +1171,10 @@ describe('ReactHooksInspectionIntegration', () => { useLabeledValue('d'); return null; } - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); const childFiber = renderer.root.findByType(Example)._currentFiber(); const tree = ReactDebugTools.inspectHooksOfFiber(childFiber); if (__DEV__) { @@ -1358,7 +1391,7 @@ describe('ReactHooksInspectionIntegration', () => { `); }); - it('should support inspectable values for nested custom hooks', () => { + it('should support inspectable values for nested custom hooks', async () => { function useInner() { React.useDebugValue('inner'); React.useState(0); @@ -1371,7 +1404,10 @@ describe('ReactHooksInspectionIntegration', () => { useOuter(); return null; } - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); const childFiber = renderer.root.findByType(Example)._currentFiber(); const tree = ReactDebugTools.inspectHooksOfFiber(childFiber); if (__DEV__) { @@ -1474,7 +1510,7 @@ describe('ReactHooksInspectionIntegration', () => { `); }); - it('should support multiple inspectable values per custom hooks', () => { + it('should support multiple inspectable values per custom hooks', async () => { function useMultiLabelCustom() { React.useDebugValue('one'); React.useDebugValue('two'); @@ -1491,7 +1527,10 @@ describe('ReactHooksInspectionIntegration', () => { useSingleLabelCustom('two'); return null; } - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); const childFiber = renderer.root.findByType(Example)._currentFiber(); const tree = ReactDebugTools.inspectHooksOfFiber(childFiber); if (__DEV__) { @@ -1684,18 +1723,21 @@ describe('ReactHooksInspectionIntegration', () => { `); }); - it('should ignore useDebugValue() made outside of a custom hook', () => { + it('should ignore useDebugValue() made outside of a custom hook', async () => { function Example() { React.useDebugValue('this is invalid'); return null; } - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); const childFiber = renderer.root.findByType(Example)._currentFiber(); const tree = ReactDebugTools.inspectHooksOfFiber(childFiber); expect(tree).toHaveLength(0); }); - it('should support an optional formatter function param', () => { + it('should support an optional formatter function param', async () => { function useCustom() { React.useDebugValue({bar: 123}, object => `bar:${object.bar}`); React.useState(0); @@ -1704,7 +1746,10 @@ describe('ReactHooksInspectionIntegration', () => { useCustom(); return null; } - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); const childFiber = renderer.root.findByType(Example)._currentFiber(); const tree = ReactDebugTools.inspectHooksOfFiber(childFiber); if (__DEV__) { @@ -1829,7 +1874,7 @@ describe('ReactHooksInspectionIntegration', () => { `); }); - it('should support an injected dispatcher', () => { + it('should support an injected dispatcher', async () => { function Foo(props) { const [state] = React.useState('hello world'); return
{state}
; @@ -1850,7 +1895,10 @@ describe('ReactHooksInspectionIntegration', () => { }, }; - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); const childFiber = renderer.root._currentFiber(); let didCatch = false; @@ -1895,7 +1943,10 @@ describe('ReactHooksInspectionIntegration', () => { return
count: {data.count}
; } - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); expect(renderer.toJSON()).toEqual({ type: 'div', props: {}, @@ -1947,7 +1998,7 @@ describe('ReactHooksInspectionIntegration', () => { `); }); - it('should support composite useSyncExternalStore hook', () => { + it('should support composite useSyncExternalStore hook', async () => { const useSyncExternalStore = React.useSyncExternalStore; function Foo() { const value = useSyncExternalStore( @@ -1959,7 +2010,10 @@ describe('ReactHooksInspectionIntegration', () => { return value; } - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); const childFiber = renderer.root.findByType(Foo)._currentFiber(); const tree = ReactDebugTools.inspectHooksOfFiber(childFiber); expect(normalizeSourceLoc(tree)).toMatchInlineSnapshot(` @@ -2010,7 +2064,7 @@ describe('ReactHooksInspectionIntegration', () => { `); }); - it('should support use(Context) hook', () => { + it('should support use(Context) hook', async () => { const Context = React.createContext('default'); function Foo() { const value = React.use(Context); @@ -2020,7 +2074,10 @@ describe('ReactHooksInspectionIntegration', () => { return value; } - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); const childFiber = renderer.root.findByType(Foo)._currentFiber(); const tree = ReactDebugTools.inspectHooksOfFiber(childFiber); expect(normalizeSourceLoc(tree)).toMatchInlineSnapshot(` @@ -2072,7 +2129,7 @@ describe('ReactHooksInspectionIntegration', () => { }); // @gate enableAsyncActions - it('should support useOptimistic hook', () => { + it('should support useOptimistic hook', async () => { const useOptimistic = React.useOptimistic; function Foo() { const [value] = useOptimistic('abc', currentState => currentState); @@ -2081,7 +2138,10 @@ describe('ReactHooksInspectionIntegration', () => { return value; } - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); const childFiber = renderer.root.findByType(Foo)._currentFiber(); const tree = ReactDebugTools.inspectHooksOfFiber(childFiber); expect(normalizeSourceLoc(tree)).toMatchInlineSnapshot(` @@ -2133,7 +2193,7 @@ describe('ReactHooksInspectionIntegration', () => { }); // @gate enableFormActions && enableAsyncActions - it('should support useFormState hook', () => { + it('should support useFormState hook', async () => { function Foo() { const [value] = ReactDOM.useFormState(function increment(n) { return n; @@ -2144,7 +2204,10 @@ describe('ReactHooksInspectionIntegration', () => { return value; } - const renderer = ReactTestRenderer.create(); + let renderer; + await act(() => { + renderer = ReactTestRenderer.create(); + }); const childFiber = renderer.root.findByType(Foo)._currentFiber(); const tree = ReactDebugTools.inspectHooksOfFiber(childFiber); expect(normalizeSourceLoc(tree)).toMatchInlineSnapshot(`