mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
fix(ui): fix typescript 4.4 errors
This commit is contained in:
committed by
Łukasz Mierzwa
parent
2ad51a5e92
commit
9dc15872a3
@@ -22,6 +22,9 @@ describe("useFetchAny", () => {
|
||||
fetchMock.mock("http://localhost/error", {
|
||||
throws: new TypeError("failed to fetch"),
|
||||
});
|
||||
fetchMock.mock("http://localhost/unknown", {
|
||||
throws: "foo",
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -168,6 +171,25 @@ describe("useFetchAny", () => {
|
||||
expect(result.current.responseURI).toBe(null);
|
||||
});
|
||||
|
||||
it("error is updated after unknown error", async () => {
|
||||
const upstreams = [{ uri: "http://localhost/unknown", options: {} }];
|
||||
const { result, waitForNextUpdate } = renderHook(() =>
|
||||
useFetchAny(upstreams)
|
||||
);
|
||||
|
||||
expect(result.current.response).toBe(null);
|
||||
expect(result.current.error).toBe(null);
|
||||
expect(result.current.inProgress).toBe(true);
|
||||
expect(result.current.responseURI).toBe(null);
|
||||
|
||||
await waitForNextUpdate();
|
||||
|
||||
expect(result.current.response).toBe(null);
|
||||
expect(result.current.error).toBe("unknown error: foo");
|
||||
expect(result.current.inProgress).toBe(false);
|
||||
expect(result.current.responseURI).toBe(null);
|
||||
});
|
||||
|
||||
it("doesn't update response after cleanup", async () => {
|
||||
fetchMock.mock(
|
||||
"http://localhost/slow/ok",
|
||||
|
||||
@@ -107,7 +107,10 @@ const useFetchAny = <T>(
|
||||
} else {
|
||||
setResponse({
|
||||
response: null,
|
||||
error: error.message,
|
||||
error:
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: `unknown error: ${error}`,
|
||||
responseURI: null,
|
||||
inProgress: false,
|
||||
});
|
||||
|
||||
@@ -18,6 +18,9 @@ describe("useFetchDelete", () => {
|
||||
fetchMock.mock("http://localhost/error", {
|
||||
throws: new TypeError("failed to fetch"),
|
||||
});
|
||||
fetchMock.mock("http://localhost/unknown", {
|
||||
throws: "foo",
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -108,6 +111,22 @@ describe("useFetchDelete", () => {
|
||||
expect(result.current.isDeleting).toBe(false);
|
||||
});
|
||||
|
||||
it("error is updated after unknown error", async () => {
|
||||
const { result, waitForNextUpdate } = renderHook(() =>
|
||||
useFetchDelete("http://localhost/unknown", EmptyOptions)
|
||||
);
|
||||
|
||||
expect(result.current.response).toBe(null);
|
||||
expect(result.current.error).toBe(null);
|
||||
expect(result.current.isDeleting).toBe(true);
|
||||
|
||||
await waitForNextUpdate();
|
||||
|
||||
expect(result.current.response).toBe(null);
|
||||
expect(result.current.error).toBe("unknown error: foo");
|
||||
expect(result.current.isDeleting).toBe(false);
|
||||
});
|
||||
|
||||
it("doesn't update response after cleanup", async () => {
|
||||
fetchMock.mock(
|
||||
"http://localhost/slow/ok",
|
||||
|
||||
@@ -45,7 +45,9 @@ const useFetchDelete = (
|
||||
}
|
||||
} catch (error) {
|
||||
if (!isCancelled) {
|
||||
setError(error.message);
|
||||
setError(
|
||||
error instanceof Error ? error.message : `unknown error: ${error}`
|
||||
);
|
||||
setIsDeleting(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@ describe("useFetchGet", () => {
|
||||
fetchMock.mock("http://localhost/error", {
|
||||
throws: new TypeError("failed to fetch"),
|
||||
});
|
||||
fetchMock.mock("http://localhost/unknown", {
|
||||
throws: "foo",
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -207,6 +210,27 @@ describe("useFetchGet", () => {
|
||||
expect(result.current.isRetrying).toBe(false);
|
||||
});
|
||||
|
||||
it("error is updated after unknown error", async () => {
|
||||
const { result, waitForNextUpdate } = renderHook(() =>
|
||||
useFetchGet<string>("http://localhost/unknown")
|
||||
);
|
||||
|
||||
expect(result.current.response).toBe(null);
|
||||
expect(result.current.error).toBe(null);
|
||||
expect(result.current.isLoading).toBe(true);
|
||||
expect(result.current.isRetrying).toBe(false);
|
||||
|
||||
for (let i = 0; i <= FetchRetryConfig.retries; i++) {
|
||||
jest.runOnlyPendingTimers();
|
||||
await waitForNextUpdate();
|
||||
}
|
||||
|
||||
expect(result.current.response).toBe(null);
|
||||
expect(result.current.error).toBe("unknown error: foo");
|
||||
expect(result.current.isLoading).toBe(false);
|
||||
expect(result.current.isRetrying).toBe(false);
|
||||
});
|
||||
|
||||
it("error is updated on uparsable JSON", async () => {
|
||||
fetchMock.mock("http://localhost/json/invalid", {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
|
||||
@@ -119,7 +119,8 @@ const useFetchGet = <T>(
|
||||
} catch (error) {
|
||||
setResponse((r) => ({
|
||||
...r,
|
||||
error: error.message,
|
||||
error:
|
||||
error instanceof Error ? error.message : `unknown error: ${error}`,
|
||||
isLoading: false,
|
||||
isRetrying: false,
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user