@@ -53,19 +53,29 @@ describe("use-db", () => {
53
53
expect ( todos ) . toStrictEqual ( [ "first" , "second" , "third" , "forth" ] ) ;
54
54
} ) ;
55
55
56
- // test("removes item from state", () => {
57
- // const { result } = renderHook(() =>
58
- // useDb("todos", { defaultValue: ["first", "second"] }),
59
- // );
60
- //
61
- // act(() => {
62
- // const removeItem = result.current[2];
63
- // removeItem();
64
- // });
65
- //
66
- // const [todos] = result.current;
67
- // expect(todos).toBeUndefined();
68
- // });
56
+ test ( "removes item from state" , ( ) => {
57
+ const { result } = renderHook ( ( ) =>
58
+ useDb ( "todos" , { defaultValue : [ "first" , "second" ] } ) ,
59
+ ) ;
60
+
61
+ {
62
+ act ( ( ) => {
63
+ const setTodos = result . current [ 1 ] ;
64
+ setTodos ( [ "third" , "forth" ] ) ;
65
+ } ) ;
66
+ const [ todos ] = result . current ;
67
+ expect ( todos ) . toStrictEqual ( [ "third" , "forth" ] ) ;
68
+ }
69
+
70
+ {
71
+ act ( ( ) => {
72
+ const removeItem = result . current [ 2 ] ;
73
+ removeItem ( ) ;
74
+ } ) ;
75
+ const [ todos ] = result . current ;
76
+ expect ( todos ) . toStrictEqual ( [ "first" , "second" ] ) ;
77
+ }
78
+ } ) ;
69
79
70
80
test ( "persists state across hook re-renders" , ( ) => {
71
81
const { result, rerender } = renderHook ( ( ) =>
0 commit comments