Skip to content

Commit

Permalink
Fix tests v2
Browse files Browse the repository at this point in the history
  • Loading branch information
OKendigelyan committed Jan 21, 2025
1 parent 59ccb13 commit e9e8d45
Show file tree
Hide file tree
Showing 4 changed files with 6,406 additions and 3,652 deletions.
5 changes: 5 additions & 0 deletions apps/web/src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ jest.doMock("@chakra-ui/react", () => ({
useColorMode: () => ({ colorMode: "light", toggleColorMode: jest.fn() }),
}));

jest.mock("@umami/utils", () => ({
...jest.requireActual("@umami/utils"),
useCustomToast: () => mockToast,
}));

jest.mock("./utils/persistor", () => ({
pause: jest.fn(),
}));
Expand Down
4 changes: 2 additions & 2 deletions packages/state/src/hooks/useAsyncActionHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe("useAsyncActionHandler", () => {
view.result.current.handleAsyncActionUnsafe(() => Promise.reject(new Error("test error")))
)
).rejects.toThrow("test error");
expect(mockToast).toHaveBeenCalledTimes(2);
expect(mockToast).toHaveBeenCalledTimes(1);
});

it("Unsafe propagates the error and shows the toast once on first handling", async () => {
Expand All @@ -181,7 +181,7 @@ describe("useAsyncActionHandler", () => {
status: "error",
isClosable: true,
});
expect(mockToast).toHaveBeenCalledTimes(2);
expect(mockToast).toHaveBeenCalledTimes(1);
});

it("Unsafe propagates the error and shows no toast on second handling", async () => {
Expand Down
9 changes: 0 additions & 9 deletions packages/state/src/hooks/useAsyncActionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useCallback, useRef, useState } from "react";

import { useAppDispatch } from "./useAppDispatch";
import { errorsActions } from "../slices";
import { mockToast } from "../testUtils";

/**
* Hook for gracefully handling async actions.
Expand Down Expand Up @@ -52,14 +51,6 @@ export const useAsyncActionHandler = () => {
...(typeof toastOptions === "function" ? toastOptions(error) : toastOptions),
});

// TODO: fix this dirty hack
mockToast({
description: errorContext.description,
status: "error",
isClosable: true,
...(typeof toastOptions === "function" ? toastOptions(error) : toastOptions),
});

dispatch(errorsActions.add(errorContext));
}
throw error;
Expand Down
Loading

1 comment on commit e9e8d45

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title Lines Statements Branches Functions
apps/desktop Coverage: 83%
83.82% (1788/2133) 79.58% (850/1068) 78.27% (454/580)
apps/web Coverage: 83%
83.82% (1788/2133) 79.58% (850/1068) 78.27% (454/580)
packages/components Coverage: 97%
97.51% (196/201) 95.91% (94/98) 88.13% (52/59)
packages/core Coverage: 81%
82.37% (215/261) 72.51% (95/131) 81.66% (49/60)
packages/crypto Coverage: 100%
100% (43/43) 90.9% (10/11) 100% (7/7)
packages/data-polling Coverage: 96%
94.63% (141/149) 87.5% (21/24) 92.85% (39/42)
packages/multisig Coverage: 98%
98.47% (129/131) 85.71% (18/21) 100% (36/36)
packages/social-auth Coverage: 100%
100% (21/21) 100% (11/11) 100% (3/3)
packages/state Coverage: 85%
84.3% (827/981) 80.5% (190/236) 77.83% (302/388)
packages/tezos Coverage: 89%
88.72% (118/133) 94.59% (35/37) 86.84% (33/38)
packages/tzkt Coverage: 89%
87.32% (62/71) 87.5% (14/16) 80.48% (33/41)

Please sign in to comment.