/
use-modal.test.tsx
36 lines (26 loc) · 1.01 KB
/
use-modal.test.tsx
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
import { renderHook } from "@testing-library/react-hooks"
import { hideOthers } from "aria-hidden"
import { MutableRefObject } from "react"
import { useAriaHidden } from "../src"
jest.mock("aria-hidden")
beforeEach(() => {
jest.clearAllMocks()
})
describe("useAriaHidden", () => {
it("should be triggered if ref.current is changed", () => {
const ref: MutableRefObject<null | HTMLElement> = { current: null }
renderHook(() => useAriaHidden(ref, true))
expect(hideOthers).not.toBeCalled()
ref.current = document.createElement("div")
renderHook(() => useAriaHidden(ref, true))
expect(hideOthers).toBeCalledWith(ref.current)
})
it("shouldn't be triggered if `shouldHide` is `false`", () => {
const ref: MutableRefObject<null | HTMLElement> = { current: null }
renderHook(() => useAriaHidden(ref, true))
expect(hideOthers).not.toBeCalled()
ref.current = document.createElement("div")
renderHook(() => useAriaHidden(ref, false))
expect(hideOthers).not.toBeCalled()
})
})