-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToast.test.tsx
More file actions
37 lines (27 loc) · 1.03 KB
/
Toast.test.tsx
File metadata and controls
37 lines (27 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { act, render, screen } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
import { userEventSetup } from "../../../test/helpers/userEventSetup";
import { AUTO_CLOSE_TIME, TOAST_ANIMATION_TIME } from "./Toast";
import { composeStories } from "@storybook/react";
import * as ToastStories from "./Toast.stories";
const { Default } = composeStories(ToastStories);
describe("Toast", () => {
beforeEach(() => {
vi.useFakeTimers({ shouldAdvanceTime: true });
});
afterEach(() => {
vi.runOnlyPendingTimers();
vi.useRealTimers();
});
test("should be show and hide toast", async () => {
const user = userEventSetup();
render(<Default />);
expect(screen.queryByRole("alert")).toBeNull();
await user.click(screen.getByRole("button"));
expect(screen.getByRole("alert")).toBeInTheDocument();
act(() => {
vi.advanceTimersByTime(TOAST_ANIMATION_TIME + AUTO_CLOSE_TIME);
});
expect(screen.queryByRole("alert")).toBeNull();
});
});