Skip to content

Commit cf792aa

Browse files
committed
Update warnings
1 parent 1e2ad2d commit cf792aa

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

src/__tests__/render.js

+23-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import ReactDOM from 'react-dom'
33
import ReactDOMServer from 'react-dom/server'
44
import {fireEvent, render, screen, configure} from '../'
55

6+
// Needs to be changed to 19.0.0 once alpha started.
7+
const isReactExperimental = React.version.startsWith('18.3.0-experimental')
8+
const isReactCanary = React.version.startsWith('18.3.0')
9+
10+
// Needs to be changed to isReactExperimental || isReactCanary once alpha started.
11+
const testGateReact18 = isReactExperimental ? test.skip : test
12+
613
describe('render API', () => {
714
let originalConfig
815
beforeEach(() => {
@@ -213,27 +220,35 @@ describe('render API', () => {
213220
expect(wrapperComponentMountEffect).toHaveBeenCalledTimes(1)
214221
})
215222

216-
test('legacyRoot uses legacy ReactDOM.render', () => {
223+
testGateReact18('legacyRoot uses legacy ReactDOM.render', () => {
217224
expect(() => {
218225
render(<div />, {legacyRoot: true})
219226
}).toErrorDev(
220-
[
221-
"Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot",
222-
],
227+
isReactCanary
228+
? [
229+
"Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://react.dev/link/switch-to-createroot",
230+
]
231+
: [
232+
"Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot",
233+
],
223234
{withoutStack: true},
224235
)
225236
})
226237

227-
test('legacyRoot uses legacy ReactDOM.hydrate', () => {
238+
testGateReact18('legacyRoot uses legacy ReactDOM.hydrate', () => {
228239
const ui = <div />
229240
const container = document.createElement('div')
230241
container.innerHTML = ReactDOMServer.renderToString(ui)
231242
expect(() => {
232243
render(ui, {container, hydrate: true, legacyRoot: true})
233244
}).toErrorDev(
234-
[
235-
"Warning: ReactDOM.hydrate is no longer supported in React 18. Use hydrateRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot",
236-
],
245+
isReactCanary
246+
? [
247+
"Warning: ReactDOM.hydrate is no longer supported in React 18. Use hydrateRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://react.dev/link/switch-to-createroot",
248+
]
249+
: [
250+
"Warning: ReactDOM.hydrate is no longer supported in React 18. Use hydrateRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot",
251+
],
237252
{withoutStack: true},
238253
)
239254
})

src/__tests__/renderHook.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import React from 'react'
22
import {renderHook} from '../pure'
33

4+
// Needs to be changed to 19.0.0 once alpha started.
5+
const isReactExperimental = React.version.startsWith('18.3.0-experimental')
6+
const isReactCanary = React.version.startsWith('18.3.0')
7+
8+
// Needs to be changed to isReactExperimental || isReactCanary once alpha started.
9+
const testGateReact18 = isReactExperimental ? test.skip : test
10+
411
test('gives committed result', () => {
512
const {result} = renderHook(() => {
613
const [state, setState] = React.useState(1)
@@ -61,7 +68,7 @@ test('allows wrapper components', async () => {
6168
expect(result.current).toEqual('provided')
6269
})
6370

64-
test('legacyRoot uses legacy ReactDOM.render', () => {
71+
testGateReact18('legacyRoot uses legacy ReactDOM.render', () => {
6572
const Context = React.createContext('default')
6673
function Wrapper({children}) {
6774
return <Context.Provider value="provided">{children}</Context.Provider>
@@ -78,9 +85,13 @@ test('legacyRoot uses legacy ReactDOM.render', () => {
7885
},
7986
).result
8087
}).toErrorDev(
81-
[
82-
"Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot",
83-
],
88+
isReactCanary
89+
? [
90+
"Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://react.dev/link/switch-to-createroot",
91+
]
92+
: [
93+
"Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot",
94+
],
8495
{withoutStack: true},
8596
)
8697
expect(result.current).toEqual('provided')

0 commit comments

Comments
 (0)