Skip to content

Commit 9d6f024

Browse files
authored
Fix react canary tests (#6115)
1 parent 1293adf commit 9d6f024

File tree

5 files changed

+69
-23
lines changed

5 files changed

+69
-23
lines changed

packages/@react-aria/interactions/test/useFocusVisible.test.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {addWindowFocusTracking, useFocusVisible, useFocusVisibleListener} from '
1414
import {hasSetupGlobalListeners} from '../src/useFocusVisible';
1515
import {mergeProps} from '@react-aria/utils';
1616
import React from 'react';
17-
import {render as ReactDOMRender} from 'react-dom';
1817
import {useButton} from '@react-aria/button';
1918
import {useFocusRing} from '@react-aria/focus';
2019

@@ -120,7 +119,7 @@ describe('useFocusVisible', function () {
120119
});
121120

122121
it('sets up focus listener in a different window', async function () {
123-
ReactDOMRender(<Example id="iframe-example" />, iframeRoot);
122+
render(<Example id="iframe-example" />, {container: iframeRoot});
124123
await waitFor(() => {
125124
expect(document.querySelector('iframe').contentWindow.document.body.querySelector('div[id="iframe-example"]')).toBeTruthy();
126125
});
@@ -184,7 +183,7 @@ describe('useFocusVisible', function () {
184183
});
185184

186185
it('removes the window object from the hasSetupGlobalListeners object on beforeunload', async function () {
187-
ReactDOMRender(<Example id="iframe-example" />, iframeRoot);
186+
render(<Example id="iframe-example" />, {container: iframeRoot});
188187
expect(hasSetupGlobalListeners.size).toBe(1);
189188
expect(hasSetupGlobalListeners.get(window)).toBeTruthy();
190189
expect(hasSetupGlobalListeners.get(iframe.contentWindow)).toBeFalsy();
@@ -203,7 +202,7 @@ describe('useFocusVisible', function () {
203202
});
204203

205204
it('removes the window object from the hasSetupGlobalListeners object if we preemptively tear down', async function () {
206-
ReactDOMRender(<Example id="iframe-example" />, iframeRoot);
205+
render(<Example id="iframe-example" />, {container: iframeRoot});
207206
expect(hasSetupGlobalListeners.size).toBe(1);
208207
expect(hasSetupGlobalListeners.get(window)).toBeTruthy();
209208
expect(hasSetupGlobalListeners.get(iframe.contentWindow)).toBeFalsy();
@@ -221,7 +220,7 @@ describe('useFocusVisible', function () {
221220
});
222221

223222
it('returns positive isFocusVisible result after toggling browser tabs after keyboard navigation', async function () {
224-
ReactDOMRender(<Example id="iframe-example" />, iframeRoot);
223+
render(<Example id="iframe-example" />, {container: iframeRoot});
225224
addWindowFocusTracking(iframeRoot);
226225

227226
// Fire focus in iframe
@@ -241,7 +240,7 @@ describe('useFocusVisible', function () {
241240
});
242241

243242
it('returns negative isFocusVisible result after toggling browser tabs without prior keyboard navigation', async function () {
244-
ReactDOMRender(<Example id="iframe-example" />, iframeRoot);
243+
render(<Example id="iframe-example" />, {container: iframeRoot});
245244
addWindowFocusTracking(iframeRoot);
246245

247246
// Fire focus in iframe
@@ -259,7 +258,7 @@ describe('useFocusVisible', function () {
259258
});
260259

261260
it('returns positive isFocusVisible result after toggling browser window after keyboard navigation', async function () {
262-
ReactDOMRender(<Example id="iframe-example" />, iframeRoot);
261+
render(<Example id="iframe-example" />, {container: iframeRoot});
263262
addWindowFocusTracking(iframeRoot);
264263

265264
// Fire focus in iframe
@@ -278,7 +277,7 @@ describe('useFocusVisible', function () {
278277
});
279278

280279
it('returns negative isFocusVisible result after toggling browser window without prior keyboard navigation', async function () {
281-
ReactDOMRender(<Example id="iframe-example" />, iframeRoot);
280+
render(<Example id="iframe-example" />, {container: iframeRoot});
282281
addWindowFocusTracking(iframeRoot);
283282

284283
// Fire focus in iframe
@@ -297,7 +296,7 @@ describe('useFocusVisible', function () {
297296
});
298297

299298
it('correctly shifts focus to the iframe when the iframe is focused', async function () {
300-
ReactDOMRender(<ButtonExample id="iframe-example" />, iframeRoot);
299+
render(<ButtonExample id="iframe-example" />, {container: iframeRoot});
301300
addWindowFocusTracking(iframeRoot);
302301

303302
// Fire focus in iframe

packages/@react-aria/overlays/stories/useModal.stories.tsx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ export const DifferentContainer = {
2828
name: 'different container'
2929
};
3030

31+
export const BadContainer = {
32+
render: () => <BadApp />,
33+
name: 'bad container',
34+
parameters: {description: {data: 'this story should crash'}}
35+
};
36+
3137
function App(props) {
3238
let [showModal, setShowModal] = useState(false);
3339
return (
@@ -64,3 +70,51 @@ function Example(props) {
6470
</OverlayProvider>
6571
);
6672
}
73+
74+
function ModalDOM2(props) {
75+
let {modalProps} = useModal();
76+
return <div data-testid={props.modalId || 'modal'} {...modalProps}>{props.children}</div>;
77+
}
78+
79+
function Modal2(props) {
80+
return (
81+
<OverlayContainer portalContainer={props.container} data-testid={props.providerId || 'modal-provider'}>
82+
<ModalDOM2 modalId={props.modalId}>{props.children}</ModalDOM2>
83+
</OverlayContainer>
84+
);
85+
}
86+
87+
function Example2(props) {
88+
return (
89+
<OverlayProvider data-testid="root-provider">
90+
<>
91+
This is the root provider.
92+
{props.children}
93+
</>
94+
</OverlayProvider>
95+
);
96+
}
97+
98+
function BadApp() {
99+
let [show1, setShow1] = useState(false);
100+
let [show2, setShow2] = useState(false);
101+
return (
102+
<div id="alternateContainer" data-testid="alternate-container">
103+
<ActionButton onPress={() => setShow1(prev => !prev)}>Toggle 1</ActionButton>
104+
{show1 && (
105+
<Example2>
106+
<div id="nestedContainer" />
107+
<ActionButton onPress={() => setShow2(prev => !prev)}>Toggle 2</ActionButton>
108+
{show2 && (
109+
<Modal2
110+
container={document.getElementById('nestedContainer')}
111+
providerId="inner-modal-provider"
112+
modalId="inner-modal">
113+
Inner
114+
</Modal2>
115+
)}
116+
</Example2>
117+
)}
118+
</div>
119+
);
120+
}

packages/@react-aria/overlays/test/useModal.test.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,6 @@ describe('useModal', function () {
180180
</div>
181181
)
182182
).toThrow();
183-
expect.extend({
184-
toHaveBeenNthCalledWithError(received, index, arg) {
185-
return {
186-
pass: received.mock.calls[index - 1].some(a => a.toString().includes(arg)),
187-
message: () => `expected console.error to include ${arg}`
188-
};
189-
}
190-
});
191-
expect(console.error).toHaveBeenNthCalledWithError(
192-
1,
193-
'An OverlayContainer must not be inside another container. Please change the portalContainer prop.'
194-
);
195183
});
196184
});
197185
});

packages/dev/test-utils/src/testSSR.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313
// Can't `import` babel, have to require?
1414
const babel = require('@babel/core');
15-
import {act} from '@testing-library/react';
15+
let act = require('react').act;
16+
if (!act) {
17+
act = require('@testing-library/react').act;
18+
}
1619
import {evaluate} from './ssrUtils';
1720
import http from 'http';
1821
import React from 'react';

scripts/setupTests.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ if (!process.env.LISTENING_TO_UNHANDLED_REJECTION) {
3333
process.env.LISTENING_TO_UNHANDLED_REJECTION = true;
3434
}
3535
const ERROR_PATTERNS_WE_SHOULD_FIX_BUT_ALLOW = [
36-
'ReactDOM.render is no longer supported in React 18'
36+
'ReactDOM.render is no longer supported in React 18',
37+
'ReactDOM.render has not been supported since React 18',
38+
'`ReactDOMTestUtils.act` is deprecated in favor of `React.act`'
3739
];
3840

3941
const WARNING_PATTERNS_WE_SHOULD_FIX_BUT_ALLOW = [];

0 commit comments

Comments
 (0)