forked from SmartDropLabs/smartdrop-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseLiveAnnouncer.test.ts
More file actions
37 lines (29 loc) · 1.22 KB
/
Copy pathuseLiveAnnouncer.test.ts
File metadata and controls
37 lines (29 loc) · 1.22 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 { renderHook } from "@/test/renderHook";
import { describe, expect, it } from "vitest";
import { useLiveAnnouncer } from "./useLiveAnnouncer";
describe("useLiveAnnouncer", () => {
it("Test 1 — returns the initial message on first render", () => {
const { result } = renderHook(() => useLiveAnnouncer("hello"));
expect(result.current).toBe("hello");
});
it("Test 2 — updates once the message value actually changes", () => {
let message = "first";
const { result, rerender } = renderHook(() => useLiveAnnouncer(message));
expect(result.current).toBe("first");
message = "second";
rerender();
expect(result.current).toBe("second");
});
it("Test 3 — re-rendering with the same message value is a no-op (still returns that value)", () => {
const message = "stable";
const { result, rerender } = renderHook(() => useLiveAnnouncer(message));
expect(result.current).toBe("stable");
rerender();
rerender();
expect(result.current).toBe("stable");
});
it("Test 4 — an empty string is a valid message (used to represent 'nothing to announce yet')", () => {
const { result } = renderHook(() => useLiveAnnouncer(""));
expect(result.current).toBe("");
});
});