From 056b72213524587e2dc6f6776da5aace56856549 Mon Sep 17 00:00:00 2001 From: Jeremy Green <20728342+jg210@users.noreply.github.com> Date: Sat, 9 Mar 2024 18:25:58 +0000 Subject: [PATCH] Attempt to test multiple overlapping onRefresh() calls. Not working. Oddly jest records test as a pass with green tick, but then there's an error backtrace and jest has non-zero exit code. --- package-lock.json | 8 ++++++++ package.json | 2 ++ src/__tests__/useRefresh.test.tsx | 23 +++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/package-lock.json b/package-lock.json index c9107fa..5d0c21f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,9 +22,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" } }, @@ -7018,6 +7020,12 @@ "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", "dev": true }, + "node_modules/@types/lodash": { + "version": "4.14.202", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.202.tgz", + "integrity": "sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ==", + "dev": true + }, "node_modules/@types/node": { "version": "20.11.25", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.25.tgz", diff --git a/package.json b/package.json index 4bf84f0..73075b0 100644 --- a/package.json +++ b/package.json @@ -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, diff --git a/src/__tests__/useRefresh.test.tsx b/src/__tests__/useRefresh.test.tsx index d73d689..ef7dbc7 100644 --- a/src/__tests__/useRefresh.test.tsx +++ b/src/__tests__/useRefresh.test.tsx @@ -1,4 +1,5 @@ import { act, renderHook, waitFor } from "@testing-library/react-native"; +//import { times } from "lodash"; import { useRefresh } from "../useRefresh"; @@ -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((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)); + // }); });