Skip to content

Commit

Permalink
Attempt to test multiple overlapping onRefresh() calls. Not working. …
Browse files Browse the repository at this point in the history
…Oddly jest records test as a pass with green tick, but then there's an error backtrace and jest has non-zero exit code.
  • Loading branch information
jg210 committed Mar 9, 2024
1 parent 476fc98 commit 056b722
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
"@tanstack/eslint-plugin-query": "5.20.1",
"@testing-library/react-native": "12.4.3",
"@types/jest": "29.5.12",
"@types/lodash": "4.14.202",
"@types/react": "18.2.45",
"eslint": "8.57.0",
"eslint-config-universe": "12.0.0",
"lodash": "4.17.21",
"typescript": "5.4.2"
},
"private": true,
Expand Down
23 changes: 23 additions & 0 deletions src/__tests__/useRefresh.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook, waitFor } from "@testing-library/react-native";
//import { times } from "lodash";

import { useRefresh } from "../useRefresh";

Expand Down Expand Up @@ -26,4 +27,26 @@ describe("useRefresh", () => {
});
waitFor(() => expect(result.current.refreshing).toEqual(false));
});

// it("multiple onRefresh calls before refetch resolves", async () => {
// let delay = 100;
// const refetch = jest.fn(() => {
// return new Promise<void>((resolve) => {
// setTimeout(() => resolve(), delay);
// delay *= 0.8;
// });
// });
// const { result } = renderHook(() => useRefresh(refetch));
// expect(refetch).toHaveBeenCalledTimes(0);
// expect(result.current.refreshing).toEqual(false);
// const numberOfRefreshes = 3;
// await act(async () => {
// times(numberOfRefreshes, async () => {
// await result.current.onRefresh();
// expect(result.current.refreshing).toEqual(true);
// });
// });
// expect(refetch).toHaveBeenCalledTimes(numberOfRefreshes);
// waitFor(() => expect(result.current.refreshing).toEqual(false));
// });
});

0 comments on commit 056b722

Please sign in to comment.