|
1 | 1 | import * as React from 'react' |
2 | 2 | import ReactDOM from 'react-dom' |
3 | | -import ReactDOMClient from 'react-dom/client' |
4 | 3 | import ReactDOMServer from 'react-dom/server' |
5 | 4 | import {fireEvent, render, screen} from '../' |
6 | 5 |
|
@@ -110,23 +109,6 @@ test('flushes useEffect cleanup functions sync on unmount()', () => { |
110 | 109 | expect(spy).toHaveBeenCalledTimes(1) |
111 | 110 | }) |
112 | 111 |
|
113 | | -test('throws if `legacyRoot: false` is used with an incomaptible version', () => { |
114 | | - const isConcurrentReact = typeof ReactDOMClient.createRoot === 'function' |
115 | | - |
116 | | - const performConcurrentRender = () => render(<div />, {legacyRoot: false}) |
117 | | - |
118 | | - // eslint-disable-next-line jest/no-if -- jest doesn't support conditional tests |
119 | | - if (isConcurrentReact) { |
120 | | - // eslint-disable-next-line jest/no-conditional-expect -- yes, jest still doesn't support conditional tests |
121 | | - expect(performConcurrentRender).not.toThrow() |
122 | | - } else { |
123 | | - // eslint-disable-next-line jest/no-conditional-expect -- yes, jest still doesn't support conditional tests |
124 | | - expect(performConcurrentRender).toThrowError( |
125 | | - `Attempted to use concurrent React with \`react-dom@${ReactDOM.version}\`. Be sure to use the \`next\` or \`experimental\` release channel (https://reactjs.org/docs/release-channels.html).`, |
126 | | - ) |
127 | | - } |
128 | | -}) |
129 | | - |
130 | 112 | test('can be called multiple times on the same container', () => { |
131 | 113 | const container = document.createElement('div') |
132 | 114 |
|
@@ -169,3 +151,28 @@ test('hydrate will make the UI interactive', () => { |
169 | 151 |
|
170 | 152 | expect(container).toHaveTextContent('clicked:1') |
171 | 153 | }) |
| 154 | + |
| 155 | +test('legacyRoot uses legacy ReactDOM.render', () => { |
| 156 | + jest.spyOn(console, 'error').mockImplementation(() => {}) |
| 157 | + render(<div />, {legacyRoot: true}) |
| 158 | + |
| 159 | + expect(console.error).toHaveBeenCalledTimes(1) |
| 160 | + expect(console.error).toHaveBeenNthCalledWith( |
| 161 | + 1, |
| 162 | + "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", |
| 163 | + ) |
| 164 | +}) |
| 165 | + |
| 166 | +test('legacyRoot uses legacy ReactDOM.hydrate', () => { |
| 167 | + jest.spyOn(console, 'error').mockImplementation(() => {}) |
| 168 | + const ui = <div /> |
| 169 | + const container = document.createElement('div') |
| 170 | + container.innerHTML = ReactDOMServer.renderToString(ui) |
| 171 | + render(ui, {container, hydrate: true, legacyRoot: true}) |
| 172 | + |
| 173 | + expect(console.error).toHaveBeenCalledTimes(1) |
| 174 | + expect(console.error).toHaveBeenNthCalledWith( |
| 175 | + 1, |
| 176 | + "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", |
| 177 | + ) |
| 178 | +}) |
0 commit comments