-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
27 lines (23 loc) · 934 Bytes
/
vitest.setup.ts
File metadata and controls
27 lines (23 loc) · 934 Bytes
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
import { vi } from 'vitest'
import '@testing-library/jest-dom'
import Tabbable from 'tabbable'
const IntersectionObserverMock = vi.fn(() => ({
disconnect: vi.fn(),
observe: vi.fn(),
takeRecords: vi.fn(),
unobserve: vi.fn()
}))
//github.com/focus-trap/tabbable#testing-in-jsdom
vi.mock('tabbable', async (): Promise<typeof Tabbable> => {
const tabbable: typeof Tabbable = await vi.importActual('tabbable')
return {
...tabbable,
tabbable: (node: Element, options) =>
tabbable.tabbable(node, { ...options, displayCheck: 'none' }),
focusable: (node, options) => tabbable.focusable(node, { ...options, displayCheck: 'none' }),
isFocusable: (node, options) =>
tabbable.isFocusable(node, { ...options, displayCheck: 'none' }),
isTabbable: (node, options) => tabbable.isTabbable(node, { ...options, displayCheck: 'none' })
}
})
vi.stubGlobal('IntersectionObserver', IntersectionObserverMock)