@@ -119,21 +119,21 @@ describe("useLocalState()", () => {
119
119
} ) ;
120
120
121
121
// todo(): this logic could be super handy...
122
- // it("updates state with callback function", () => {
123
- // const key = "todos";
124
- // const values = ["first", "second"];
125
- // const { result } = renderHook(() => useLocalState(key, values));
122
+ it ( "updates state with callback function" , ( ) => {
123
+ const key = "todos" ;
124
+ const values = [ "first" , "second" ] ;
125
+ const { result } = renderHook ( ( ) => useLocalState ( key , values ) ) ;
126
126
127
- // const newValues = ["first", "second"];
128
- // act(() => {
129
- // const setTodos = result.current[1];
127
+ const newValues = [ "first" , "second" ] ;
128
+ act ( ( ) => {
129
+ const setTodos = result . current [ 1 ] ;
130
130
131
- // setTodos((current) => [...current, ...newValues]);
132
- // });
131
+ setTodos ( ( current ) => [ ...current , ...newValues ] ) ;
132
+ } ) ;
133
133
134
- // const [todos] = result.current;
135
- // expect(todos).toEqual([...values, ...newValues]);
136
- // });
134
+ const [ todos ] = result . current ;
135
+ expect ( todos ) . toEqual ( [ ...values , ...newValues ] ) ;
136
+ } ) ;
137
137
138
138
it ( "does not fail even if invalid data is stored into localStorage" , async ( ) => {
139
139
if ( ! SUPPORTED ) return ;
@@ -165,24 +165,6 @@ describe("useLocalState()", () => {
165
165
expect ( todos ) . toEqual ( values ) ;
166
166
} ) ;
167
167
168
- it ( "throws an error on two states with the same key" , async ( ) => {
169
- const consoleError = console . error ;
170
- console . error = ( ) => null ;
171
-
172
- const key = "todos" ;
173
- const valuesA = [ "first" , "second" ] ;
174
- const valuesB = [ "third" , "fourth" ] ;
175
-
176
- expect ( ( ) => {
177
- renderHook ( ( ) => {
178
- useLocalState ( key , valuesA ) ;
179
- useLocalState ( key , valuesB ) ;
180
- } ) ;
181
- } ) . toThrow ( ) ;
182
-
183
- console . error = consoleError ;
184
- } ) ;
185
-
186
168
it ( "does not throw an error with two states with different keys" , async ( ) => {
187
169
const keyA = "todos" ;
188
170
const keyB = "todos" ;
0 commit comments