Skip to content

Commit 0838c62

Browse files
committed
Replace @testing-library/react-hooks with @testing-library/react
- The `renderHook` method in `@testing-library/react-hooks` has now been moved to `@testing-library/react`. This commit updates imports and usages of the `renderHook` function to comply with the new syntax requirements in the [react-hooks-testing-library migration guide](https://github.com/testing-library/react-hooks-testing-library/blob/chore/migration-guide/MIGRATION_GUIDE.md#waitfornextupdate).
1 parent a6c26c0 commit 0838c62

File tree

4 files changed

+4
-43
lines changed

4 files changed

+4
-43
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
"@reduxjs/toolkit": "^2.0.0-beta.4",
8282
"@testing-library/jest-dom": "^6.4.5",
8383
"@testing-library/react": "^15.0.7",
84-
"@testing-library/react-hooks": "^8.0.1",
8584
"@types/node": "^20.11.6",
8685
"@types/prop-types": "^15.7.12",
8786
"@types/react": "npm:types-react@19.0.0-beta.1",

test/hooks/useDispatch.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { renderHook } from '@testing-library/react-hooks'
1+
import { renderHook } from '@testing-library/react'
22
import React from 'react'
33
import type { ProviderProps, ReactReduxContextValue } from 'react-redux'
44
import {

test/hooks/useReduxContext.spec.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
createReduxContextHook,
33
useReduxContext,
44
} from '@internal/hooks/useReduxContext'
5-
import { renderHook } from '@testing-library/react-hooks'
5+
import { renderHook } from '@testing-library/react'
66
import { createContext } from 'react'
77
import type { ReactReduxContextValue } from 'react-redux'
88

@@ -12,9 +12,7 @@ describe('React', () => {
1212
it('throws if component is not wrapped in provider', () => {
1313
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
1414

15-
const { result } = renderHook(() => useReduxContext())
16-
17-
expect(result.error?.message).toMatch(
15+
expect(() => renderHook(() => useReduxContext())).toThrowError(
1816
/could not find react-redux context value/,
1917
)
2018

@@ -27,9 +25,7 @@ describe('React', () => {
2725
const useCustomReduxContext = createReduxContextHook(customContext)
2826
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
2927

30-
const { result } = renderHook(() => useCustomReduxContext())
31-
32-
expect(result.error?.message).toMatch(
28+
expect(() => renderHook(() => useCustomReduxContext())).toThrowError(
3329
/could not find react-redux context value/,
3430
)
3531

yarn.lock

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,28 +2229,6 @@ __metadata:
22292229
languageName: node
22302230
linkType: hard
22312231

2232-
"@testing-library/react-hooks@npm:^8.0.1":
2233-
version: 8.0.1
2234-
resolution: "@testing-library/react-hooks@npm:8.0.1"
2235-
dependencies:
2236-
"@babel/runtime": "npm:^7.12.5"
2237-
react-error-boundary: "npm:^3.1.0"
2238-
peerDependencies:
2239-
"@types/react": ^16.9.0 || ^17.0.0
2240-
react: ^16.9.0 || ^17.0.0
2241-
react-dom: ^16.9.0 || ^17.0.0
2242-
react-test-renderer: ^16.9.0 || ^17.0.0
2243-
peerDependenciesMeta:
2244-
"@types/react":
2245-
optional: true
2246-
react-dom:
2247-
optional: true
2248-
react-test-renderer:
2249-
optional: true
2250-
checksum: 10/f7b69373feebe99bc7d60595822cc5c00a1a5a4801bc4f99b597256a5c1d23c45a51f359051dd8a7bdffcc23b26f324c582e9433c25804934fd351a886812790
2251-
languageName: node
2252-
linkType: hard
2253-
22542232
"@testing-library/react@npm:^15.0.7":
22552233
version: 15.0.7
22562234
resolution: "@testing-library/react@npm:15.0.7"
@@ -7031,17 +7009,6 @@ __metadata:
70317009
languageName: node
70327010
linkType: hard
70337011

7034-
"react-error-boundary@npm:^3.1.0":
7035-
version: 3.1.4
7036-
resolution: "react-error-boundary@npm:3.1.4"
7037-
dependencies:
7038-
"@babel/runtime": "npm:^7.12.5"
7039-
peerDependencies:
7040-
react: ">=16.13.1"
7041-
checksum: 10/7418637bf352b88f35ff3798e6faa094ee046df9d422fc08f54c017892c3c0738dac661ba3d64d97209464e7a60e7fbbeffdbeaee5edc38f3aaf5f1f4a8bf610
7042-
languageName: node
7043-
linkType: hard
7044-
70457012
"react-is@npm:^16.13.1":
70467013
version: 16.13.1
70477014
resolution: "react-is@npm:16.13.1"
@@ -7081,7 +7048,6 @@ __metadata:
70817048
"@reduxjs/toolkit": "npm:^2.0.0-beta.4"
70827049
"@testing-library/jest-dom": "npm:^6.4.5"
70837050
"@testing-library/react": "npm:^15.0.7"
7084-
"@testing-library/react-hooks": "npm:^8.0.1"
70857051
"@types/node": "npm:^20.11.6"
70867052
"@types/prop-types": "npm:^15.7.12"
70877053
"@types/react": "npm:types-react@19.0.0-beta.1"

0 commit comments

Comments
 (0)