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

Function stubPipWindow

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

Source from the content-addressed store, hash-verified

442 >
443
444 function stubPipWindow(
445 overrides: Partial<
446 Pick<FakePipWindow, 'innerWidth' | 'innerHeight'>
447 > = {},
448 ) {
449 const pipDocument = document.implementation.createHTMLDocument('PiP')
450 const listeners = new Map<string, EventListener>()
451 const fakeWindow: FakePipWindow = {
452 document: pipDocument,
453 innerWidth: 800,
454 innerHeight: 600,
455 addEventListener: vi.fn((event: string, handler: EventListener) => {
456 listeners.set(event, handler)
457 }),
458 removeEventListener: vi.fn((event: string) => {
459 listeners.delete(event)
460 }),
461 close: vi.fn(),
462 ...overrides,
463 }
464 const open = vi.fn(() => fakeWindow)
465 vi.stubGlobal('open', open)
466 return {
467 pipDocument,
468 fakeWindow,
469 open,
470 fire: (event: string) => {
471 listeners.get(event)?.(new Event(event))
472 },
473 }
474 }
475
476 it('should open a PiP window when the picture-in-picture button is clicked', () => {
477 const { open } = stubPipWindow()

Callers 1

Devtools.test.tsxFile · 0.70

Calls 1

getMethod · 0.80

Tested by

no test coverage detected