File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ import { act , renderHook } from '@testing-library/react-hooks' ;
2+ import useQueryParams from '../src/useQueryParams' ;
3+
4+ describe ( 'useQueryParams' , ( ) => {
5+ it ( 'should be able to set query params' , ( ) => {
6+ const newParams = { page : '1' , order : 'ASC' } ;
7+ const { result } = renderHook ( ( ) => useQueryParams ( ) ) ;
8+
9+ act ( ( ) => {
10+ result . current . setParams ( newParams ) ;
11+ } ) ;
12+ const params = result . current . getParams ( ) ;
13+ expect ( params ) . toStrictEqual ( newParams ) ;
14+ } ) ;
15+
16+ it ( 'should be able to clear query params' , ( ) => {
17+ const { result } = renderHook ( ( ) => useQueryParams ( ) ) ;
18+
19+ act ( ( ) => {
20+ result . current . setParams ( { } ) ;
21+ } ) ;
22+ const params = result . current . getParams ( ) ;
23+ expect ( params ) . toStrictEqual ( { } ) ;
24+ } ) ;
25+
26+ it ( 'should be able to read query params' , ( ) => {
27+ delete window . location ;
28+ window . location = new URL ( 'https://test.com/testing?param1=test&testing=true' ) ;
29+
30+ const { result } = renderHook ( ( ) => useQueryParams ( ) ) ;
31+ let params ;
32+ act ( ( ) => {
33+ params = result . current . getParams ( ) ;
34+ } ) ;
35+ expect ( params ) . toStrictEqual ( { param1 : 'test' , testing : 'true' } ) ;
36+ } ) ;
37+ } ) ;
You can’t perform that action at this time.
0 commit comments