Skip to content

Commit 87ba8fc

Browse files
authored
add support for react 18 (#7)
1 parent e7d912e commit 87ba8fc

4 files changed

Lines changed: 32 additions & 25 deletions

File tree

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
4444
"access": "public"
4545
},
4646
"devDependencies": {
47-
"@testing-library/jest-dom": "^5.16.4",
48-
"@testing-library/react": "^12.0.0",
49-
"@testing-library/react-hooks": "^8.0.1",
47+
"@testing-library/jest-dom": "^5.16.5",
48+
"@testing-library/react": "^13.4.0",
5049
"@types/jest": "^28.1.3",
51-
"@types/react": "^17.0.0",
50+
"@types/react": "^18.0.0",
51+
"@types/react-dom": "^18.0.0",
5252
"@types/react-router-dom": "^5.3.3",
5353
"@typescript-eslint/eslint-plugin": "^5.30.0",
5454
"@typescript-eslint/parser": "^5.30.0",
@@ -59,18 +59,18 @@
5959
"eslint-plugin-prettier": "^4.1.0",
6060
"jest": "^28.1.1",
6161
"jest-environment-jsdom": "^28.1.1",
62-
"next": "^12.2.0",
62+
"next": "^13.1.3",
6363
"next-router-mock": "^0.7.4",
6464
"prettier": "^2.7.1",
65-
"react": "^17.0.2",
66-
"react-dom": "^17.0.2",
67-
"react-router-dom": "^6.3.0",
65+
"react": "^18.0.0",
66+
"react-dom": "^18.0.0",
67+
"react-router-dom": "^6.7.0",
6868
"ts-jest": "^28.0.5",
6969
"typescript": "^4.7.4"
7070
},
7171
"peerDependencies": {
72-
"next": "^12.0.0",
73-
"react": "^16.0.0 || ^17.0.0",
72+
"next": "^12.0.0 || ^13.0.0",
73+
"react": "^16.0.0 || ^17.0.0 || ^18.0.0",
7474
"react-router-dom": "^6.0.0"
7575
},
7676
"peerDependenciesMeta": {

src/__test__/inMemoryPagination.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { act, renderHook } from '@testing-library/react-hooks'
1+
import { act, renderHook } from '@testing-library/react'
22
import { useQueryAndPagination } from '../inMemoryPagination'
33
import { IndexType } from '../types'
44

src/__test__/nextRouterPagination.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// eslint-disable-next-line @typescript-eslint/no-unused-vars
22
import React from 'react'
3-
import { act, renderHook } from '@testing-library/react-hooks'
3+
import { act, renderHook } from '@testing-library/react'
44
import router from 'next/router'
55

66
import { useQueryAndPagination } from '../nextRouterPagination'

src/__test__/reactRouterPagination.test.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
1-
import React from 'react'
2-
import { act, renderHook } from '@testing-library/react-hooks'
1+
import React, { ReactNode } from 'react'
2+
import { act, renderHook } from '@testing-library/react'
33
import { BrowserRouter as Router } from 'react-router-dom'
44
import { useQueryAndPagination } from '../reactRouterPagination'
55
import { IndexType } from '../types'
6-
const wrapper: React.FC = ({ children }) => <Router>{children}</Router>
6+
7+
function Wrapper({ children }: { children?: ReactNode }) {
8+
return <Router>{children}</Router>
9+
}
710

811
beforeEach(() => {
912
window.history.pushState({}, '', '/')
1013
})
1114

1215
test('should initialize pagination', () => {
13-
const { result } = renderHook(() => useQueryAndPagination(), { wrapper })
16+
const { result } = renderHook(() => useQueryAndPagination(), {
17+
wrapper: Wrapper,
18+
})
1419

1520
expect(result.current.page).toBe(0)
1621
expect(result.current.size).toBe(15)
1722
})
1823

1924
test('should change page', () => {
20-
const { result } = renderHook(() => useQueryAndPagination(), { wrapper })
25+
const { result } = renderHook(() => useQueryAndPagination(), {
26+
wrapper: Wrapper,
27+
})
2128

2229
act(() => {
2330
result.current.actions.setPage(2)
@@ -30,7 +37,7 @@ test('should change page', () => {
3037
test('should change search', () => {
3138
const { result } = renderHook(
3239
() => useQueryAndPagination({ defaultQueryParameters: { search: '' } }),
33-
{ wrapper }
40+
{ wrapper: Wrapper }
3441
)
3542

3643
act(() => {
@@ -44,7 +51,7 @@ test('should change search', () => {
4451
test('clear pagination should reset search and page', () => {
4552
const { result } = renderHook(
4653
() => useQueryAndPagination({ defaultQueryParameters: { search: '' } }),
47-
{ wrapper }
54+
{ wrapper: Wrapper }
4855
)
4956

5057
act(() => {
@@ -71,7 +78,7 @@ test('change default parameters', () => {
7178
const { result } = renderHook(
7279
() =>
7380
useQueryAndPagination({ indexType: IndexType.ONE_BASED, pageSize: 10 }),
74-
{ wrapper }
81+
{ wrapper: Wrapper }
7582
)
7683

7784
expect(result.current.page).toBe(1)
@@ -84,7 +91,7 @@ test('query multiple different properties, should keep them all', () => {
8491
useQueryAndPagination({
8592
defaultQueryParameters: { search: '', department: '' },
8693
}),
87-
{ wrapper }
94+
{ wrapper: Wrapper }
8895
)
8996

9097
act(() => {
@@ -102,7 +109,7 @@ test('query a property that is not configured, should do nothing', () => {
102109
useQueryAndPagination({
103110
defaultQueryParameters: { search: '' },
104111
}),
105-
{ wrapper }
112+
{ wrapper: Wrapper }
106113
)
107114

108115
act(() => {
@@ -121,7 +128,7 @@ test('properties in the URL, that are not part of the configuration should be le
121128
useQueryAndPagination({
122129
defaultQueryParameters: { search: '' },
123130
}),
124-
{ wrapper }
131+
{ wrapper: Wrapper }
125132
)
126133

127134
act(() => {
@@ -141,7 +148,7 @@ test('query property with default value, should remove it from url', () => {
141148
useQueryAndPagination({
142149
defaultQueryParameters: { search: '' },
143150
}),
144-
{ wrapper }
151+
{ wrapper: Wrapper }
145152
)
146153

147154
act(() => {
@@ -158,7 +165,7 @@ test('query property with empty value and different default value', () => {
158165
useQueryAndPagination({
159166
defaultQueryParameters: { search: 'Default search' },
160167
}),
161-
{ wrapper }
168+
{ wrapper: Wrapper }
162169
)
163170

164171
act(() => {

0 commit comments

Comments
 (0)