Skip to content

Commit 7c6a8e6

Browse files
committed
chore: add test case for global snackbar
1 parent 18cf563 commit 7c6a8e6

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

site/src/hooks/useClipboard.temp.test.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { act, renderHook } from "@testing-library/react";
1+
import { act, renderHook, screen } from "@testing-library/react";
22
import { GlobalSnackbar } from "components/GlobalSnackbar/GlobalSnackbar";
33
import { ThemeProvider } from "contexts/ThemeProvider";
44
import {
@@ -166,8 +166,8 @@ describe.each(secureContextValues)("useClipboard - secure: %j", (isSecure) => {
166166
// Because of timing trickery, any timeouts for flipping the copy status
167167
// back to false will trigger before the test can complete. This will never
168168
// be an issue in the real world, but it will kick up 'act' warnings in the
169-
// console, which makes tests more annoying. Just wait for them to finish up
170-
// to avoid anything from being logged, but note that the value of
169+
// console, which makes tests more annoying. Just waiting for them to finish
170+
// up to avoid anything from being logged, but note that the value of
171171
// showCopiedSuccess will become false after this
172172
await act(() => jest.runAllTimersAsync());
173173

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

201-
it.skip("Should dispatch a new toast message to the global snackbar if no callback is provided", async () => {
202-
expect.hasAssertions();
201+
it("Should dispatch a new toast message to the global snackbar if no callback is provided", async () => {
202+
const textToCopy = "crow";
203+
const { result } = renderUseClipboard({ textToCopy });
204+
205+
setSimulateFailure(true);
206+
await act(() => result.current.copyToClipboard());
207+
208+
const errorMessageNode = screen.queryByText(COPY_FAILED_MESSAGE);
209+
expect(errorMessageNode).not.toBeNull();
203210
});
204211
});

0 commit comments

Comments
 (0)