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'
33import { BrowserRouter as Router } from 'react-router-dom'
44import { useQueryAndPagination } from '../reactRouterPagination'
55import { 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
811beforeEach ( ( ) => {
912 window . history . pushState ( { } , '' , '/' )
1013} )
1114
1215test ( '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
1924test ( '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', () => {
3037test ( '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', () => {
4451test ( '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