Skip to content

Commit

Permalink
add tests for previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
maradotwebp committed Sep 18, 2023
1 parent e3683a7 commit 8fd631e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/react/src/retrieval/useMany.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { User } from "../testutils";
import React from "react";
import { createDB, createTable, insert, insertMany, Table } from "blinkdb";
import { createDB, createTable, insert, insertMany, Query, Table } from "blinkdb";
import { renderHook, waitFor } from "@testing-library/react";
import { useMany } from "./useMany";

Expand Down Expand Up @@ -33,6 +33,23 @@ test("shows done state on subsequent renders", async () => {
expect(result.current.data).toStrictEqual([]);
});

test("restarts fetching when the query changes", async () => {
await insertMany(userTable, users);
const { result, rerender } = renderHook((props) => useMany(userTable, props.query), {
initialProps: { query: {} as Query<User, "id"> }
});

await waitFor(() => {
expect(result.current.data).toStrictEqual(users);
});

rerender({ query: { where: { id: "1" } } });

await waitFor(() => {
expect(result.current.data).toStrictEqual(users.filter(u => u.id === "1"));
});
});

describe("without filter", () => {

beforeEach(async () => {
Expand Down

0 comments on commit 8fd631e

Please sign in to comment.