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

Function stubPipWindow

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

Source from the content-addressed store, hash-verified

416 >
417
418 function stubPipWindow(
419 overrides: Partial<
420 Pick<FakePipWindow, 'innerWidth' | 'innerHeight'>
421 > = {},
422 ) {
423 const pipDocument = document.implementation.createHTMLDocument('PiP')
424 const listeners = new Map<string, EventListener>()
425 const fakeWindow: FakePipWindow = {
426 document: pipDocument,
427 innerWidth: 800,
428 innerHeight: 600,
429 addEventListener: vi.fn((event: string, handler: EventListener) => {
430 listeners.set(event, handler)
431 }),
432 removeEventListener: vi.fn((event: string) => {
433 listeners.delete(event)
434 }),
435 close: vi.fn(),
436 ...overrides,
437 }
438 const open = vi.fn(() => fakeWindow)
439 vi.stubGlobal('open', open)
440 return {
441 pipDocument,
442 fakeWindow,
443 open,
444 fire: (event: string) => {
445 listeners.get(event)?.(new Event(event))
446 },
447 }
448 }
449
450 it('should open a PiP window when the picture-in-picture button is clicked', () => {
451 const { open } = stubPipWindow()

Callers 1

Devtools.test.tsxFile · 0.70

Calls 1

getMethod · 0.80

Tested by

no test coverage detected