Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

mockVisibilityState.ts

12 lines456 Bytes

1import { vi } from 'vitest'
2import type { MockInstance } from 'vitest'
3​
4/**
5 * Mocks `document.visibilityState` to return a given value.
6 * @param value - The visibility state to return.
7 * @returns The spy, to restore the original getter with `mockRestore()`.
8 */
9export const mockVisibilityState = (
10 value: DocumentVisibilityState,
11): MockInstance<() => DocumentVisibilityState> =>
12 vi.spyOn(document, 'visibilityState', 'get').mockReturnValue(value)