import '@testing-library/jest-dom' import { setCoreRuntime } from '@/core/runtime' import { testCoreRuntime } from './helpers/core' // The application runs on the real core (R2): the shipped wasm build, loaded from disk. setCoreRuntime(await testCoreRuntime()) // happy-dom has no hit testing: `elementsFromPoint` answers the element the pointerdown // being dispatched targets, then its ancestors (top first, as a browser would), whatever // the coordinates. The editor's press machine reads the press's target through it. function stubHitTesting(doc: Document): void { let pressed: Element | null = null doc.addEventListener( 'pointerdown', (event) => { pressed = event.target instanceof Element ? event.target : null }, true, ) Object.defineProperty(doc, 'elementsFromPoint', { configurable: true, value: () => { const chain: Element[] = [] for (let el = pressed; el; el = el.parentElement) chain.push(el) return chain }, }) } // Node-environment suites have no document. if (typeof document !== 'undefined') stubHitTesting(document)