Skip to content

Commit 448deab

Browse files
committed
✅ add "removes item from state" test
1 parent 0e1c1ec commit 448deab

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

Diff for: test.ts

+23-13
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,29 @@ describe("use-db", () => {
5353
expect(todos).toStrictEqual(["first", "second", "third", "forth"]);
5454
});
5555

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+
});
6979

7080
test("persists state across hook re-renders", () => {
7181
const { result, rerender } = renderHook(() =>

0 commit comments

Comments
 (0)