MCPcopy Create free account
hub / github.com/TanStack/query / stubPipWindow

Function stubPipWindow

packages/query-devtools/src/__tests__/Devtools.test.tsx:1052–1095  ·  view source on GitHub ↗
(
      overrides: Partial<
        Pick<FakePipWindow, 'innerWidth' | 'innerHeight'>
      > = {},
    )

Source from the content-addressed store, hash-verified

1050 >
1051
1052 function stubPipWindow(
1053 overrides: Partial<
1054 Pick<FakePipWindow, 'innerWidth' | 'innerHeight'>
1055 > = {},
1056 ) {
1057 const pipDocument = document.implementation.createHTMLDocument('PiP')
1058 Object.defineProperty(pipDocument, 'defaultView', { value: window })
1059 const listeners = new Map<string, EventListener>()
1060 const fakeWindow: FakePipWindow = {
1061 document: pipDocument,
1062 innerWidth: 800,
1063 innerHeight: 600,
1064 addEventListener: vi.fn<
1065 (event: string, handler: EventListener) => void
1066 >((event: string, handler: EventListener) => {
1067 listeners.set(event, handler)
1068 }),
1069 removeEventListener: vi.fn<(event: string) => void>((event: string) => {
1070 listeners.delete(event)
1071 }),
1072 close: vi.fn<() => void>(),
1073 ...overrides,
1074 }
1075 const open = vi.fn<
1076 () => Pick<
1077 Window,
1078 | 'close'
1079 | 'addEventListener'
1080 | 'removeEventListener'
1081 | 'document'
1082 | 'innerWidth'
1083 | 'innerHeight'
1084 >
1085 >(() => fakeWindow)
1086 vi.stubGlobal('open', open)
1087 return {
1088 pipDocument,
1089 fakeWindow,
1090 open,
1091 fire: (event: string) => {
1092 listeners.get(event)?.(new Event(event))
1093 },
1094 }
1095 }
1096
1097 it('should open a PiP window when the picture-in-picture button is clicked', () => {
1098 const { open } = stubPipWindow()

Callers 1

Devtools.test.tsxFile · 0.70

Calls 1

getMethod · 0.80

Tested by

no test coverage detected