Skip to content

Commit 0fb349c

Browse files
committed
feat: increase coverage to fix ci
1 parent e155799 commit 0fb349c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/__tests__/renderHook.js

+23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import React from 'react'
2+
import ReactDOM from 'react-dom'
3+
24
import {renderHook} from '../pure'
35

46
const isReact18 = React.version.startsWith('18.')
@@ -136,3 +138,24 @@ test('throws error when both initialProps and initialArgs are used', () => {
136138
renderHook(useTestHook, {initialProps: 1, initialArgs: [2, 3]}),
137139
).toThrow('Cannot use both initialProps and initialArgs. Choose one.')
138140
})
141+
142+
test('throws an error when legacyRoot is used in unsupported React versions', () => {
143+
const useTestHook = () => 'test'
144+
145+
// Save the original ReactDOM.render
146+
const {render: originalRender} = ReactDOM
147+
148+
// Mock by direct assignment
149+
ReactDOM.render = undefined
150+
151+
expect(() => {
152+
renderHook(useTestHook, {legacyRoot: true})
153+
}).toThrowError(
154+
'`legacyRoot: true` is not supported in this version of React. ' +
155+
'If your app runs React 19 or later, you should remove this flag. ' +
156+
'If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.',
157+
)
158+
159+
// Restore the original
160+
ReactDOM.render = originalRender
161+
})

0 commit comments

Comments
 (0)