@@ -75,6 +75,24 @@ describe(useSearchParamsKey.name, () => {
75
75
expect ( search . get ( key ) ) . toEqual ( null ) ;
76
76
} ) ;
77
77
78
+ it ( "Will dispatch state changes through custom URLSearchParams value if provided" , async ( ) => {
79
+ const key = "love" ;
80
+ const initialValue = "dogs" ;
81
+ const customParams = new URLSearchParams ( { [ key ] : initialValue } ) ;
82
+
83
+ const { result } = await renderHookWithAuth (
84
+ ( { key } ) => useSearchParamsKey ( { key, searchParams : customParams } ) ,
85
+ {
86
+ routingOptions : { route : `/?=${ key } =${ initialValue } ` } ,
87
+ renderOptions : { initialProps : { key } } ,
88
+ } ,
89
+ ) ;
90
+
91
+ const newValue = "all animals" ;
92
+ void act ( ( ) => result . current . setValue ( newValue ) ) ;
93
+ await waitFor ( ( ) => expect ( customParams . get ( key ) ) . toEqual ( newValue ) ) ;
94
+ } ) ;
95
+
78
96
it ( "Does not have methods change previous values if 'key' argument changes during re-renders" , async ( ) => {
79
97
const readonlyKey = "readonlyKey" ;
80
98
const mutableKey = "mutableKey" ;
@@ -100,22 +118,4 @@ describe(useSearchParamsKey.name, () => {
100
118
expect ( search . get ( readonlyKey ) ) . toEqual ( initialReadonlyValue ) ;
101
119
expect ( search . get ( mutableKey ) ) . toEqual ( swapValue ) ;
102
120
} ) ;
103
-
104
- it ( "Will dispatch state changes through custom URLSearchParams value if provided" , async ( ) => {
105
- const key = "love" ;
106
- const initialValue = "dogs" ;
107
- const customParams = new URLSearchParams ( { [ key ] : initialValue } ) ;
108
-
109
- const { result } = await renderHookWithAuth (
110
- ( { key } ) => useSearchParamsKey ( { key, searchParams : customParams } ) ,
111
- {
112
- routingOptions : { route : `/?=${ key } =${ initialValue } ` } ,
113
- renderOptions : { initialProps : { key } } ,
114
- } ,
115
- ) ;
116
-
117
- const newValue = "all animals" ;
118
- void act ( ( ) => result . current . setValue ( newValue ) ) ;
119
- await waitFor ( ( ) => expect ( customParams . get ( key ) ) . toEqual ( newValue ) ) ;
120
- } ) ;
121
121
} ) ;
0 commit comments