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

Function stubPipWindow

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

Source from the content-addressed store, hash-verified

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

Callers 1

Devtools.test.tsxFile · 0.70

Calls 1

getMethod · 0.80

Tested by

no test coverage detected