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

Function stubPipWindow

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

Source from the content-addressed store, hash-verified

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

Callers 1

Devtools.test.tsxFile · 0.70

Calls 1

getMethod · 0.80

Tested by

no test coverage detected