Skip to content

fix: update tests for useClipboard to minimize risks of flakes #13250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 15, 2024
Prev Previous commit
Next Next commit
chore: add test case for global snackbar
  • Loading branch information
Parkreiner committed May 12, 2024
commit 7c6a8e69453eb3df043b01c83a1ecdcf5f45efcf
17 changes: 12 additions & 5 deletions site/src/hooks/useClipboard.temp.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { act, renderHook } from "@testing-library/react";
import { act, renderHook, screen } from "@testing-library/react";
import { GlobalSnackbar } from "components/GlobalSnackbar/GlobalSnackbar";
import { ThemeProvider } from "contexts/ThemeProvider";
import {
Expand Down Expand Up @@ -166,8 +166,8 @@ describe.each(secureContextValues)("useClipboard - secure: %j", (isSecure) => {
// Because of timing trickery, any timeouts for flipping the copy status
// back to false will trigger before the test can complete. This will never
// be an issue in the real world, but it will kick up 'act' warnings in the
// console, which makes tests more annoying. Just wait for them to finish up
// to avoid anything from being logged, but note that the value of
// console, which makes tests more annoying. Just waiting for them to finish
// up to avoid anything from being logged, but note that the value of
// showCopiedSuccess will become false after this
await act(() => jest.runAllTimersAsync());

Expand Down Expand Up @@ -198,7 +198,14 @@ describe.each(secureContextValues)("useClipboard - secure: %j", (isSecure) => {
expect(onError).toBeCalled();
});

it.skip("Should dispatch a new toast message to the global snackbar if no callback is provided", async () => {
expect.hasAssertions();
it("Should dispatch a new toast message to the global snackbar if no callback is provided", async () => {
const textToCopy = "crow";
const { result } = renderUseClipboard({ textToCopy });

setSimulateFailure(true);
await act(() => result.current.copyToClipboard());

const errorMessageNode = screen.queryByText(COPY_FAILED_MESSAGE);
expect(errorMessageNode).not.toBeNull();
});
});